Boost logo

Boost-Commit :

From: jurko.gospodnetic_at_[hidden]
Date: 2008-06-07 19:46:46


Author: jurko
Date: 2008-06-07 19:46:46 EDT (Sat, 07 Jun 2008)
New Revision: 46225
URL: http://svn.boost.org/trac/boost/changeset/46225

Log:
Updated the vector class defined in Boost Build's containers.jam module. vector.empty() rule no longer returns true for a non empty container containing only empty strings. Removed vector.indices() rule that had a defective implementation causing vector.equal() to compare only the first and last vector element (reported by Rick Yang). Corrected the vector.equal() rule. Added new vector class related tests. Minor stylistic changes.
Text files modified:
   trunk/tools/build/v2/util/container.jam | 54 +++++++++++++++++----------------------
   1 files changed, 24 insertions(+), 30 deletions(-)

Modified: trunk/tools/build/v2/util/container.jam
==============================================================================
--- trunk/tools/build/v2/util/container.jam (original)
+++ trunk/tools/build/v2/util/container.jam 2008-06-07 19:46:46 EDT (Sat, 07 Jun 2008)
@@ -6,9 +6,6 @@
 
 # Various container classes.
 
-import "class" : * ;
-
-
 # Base for container objects. This lets us construct recursive structures. That
 # is containers with containers in them, specifically so we can tell literal
 # values from node values.
@@ -45,12 +42,12 @@
 #
 class vector : node
 {
- import numbers : range ;
+ import numbers ;
     import utility ;
     import sequence ;
 
     rule __init__ (
- values * # Initial contents of vector.
+ values * # Initial contents of vector.
     )
     {
         node.__init__ ;
@@ -80,7 +77,7 @@
     rule at (
         index # The element index, one based.
         : * # Additional indices to access recursively.
- )
+ )
     {
         local r = $(self.value[$(index)]) ;
         if $(2)
@@ -97,7 +94,7 @@
     rule get-at (
         index # The element index, one based.
         : * # Additional indices to access recursively.
- )
+ )
     {
         local r = $(self.value[$(index)]) ;
         if $(2)
@@ -112,7 +109,7 @@
     #
     rule push-front (
         value # Value to become first element.
- )
+ )
     {
         self.value = $(value) $(self.value) ;
     }
@@ -128,8 +125,8 @@
     # Add the given value at the end of the vector.
     #
     rule push-back (
- value # Value to become back element.
- )
+ value # Value to become back element.
+ )
     {
         self.value += $(value) ;
     }
@@ -150,7 +147,7 @@
     rule insert (
         index # The index to insert at, one based.
         : value # The value to insert.
- )
+ )
     {
         local left = $(self.value[1-$(index)]) ;
         local right = $(self.value[$(index)-]) ;
@@ -165,9 +162,9 @@
     # not specifying an end is equivalent to the [start, start] range.
     #
     rule erase (
- start # Index of first element ro remove.
+ start # Index of first element to remove.
         end ? # Optional, index of last element to remove.
- )
+ )
     {
         end ?= $(start) ;
         local left = $(self.value[1-$(start)]) ;
@@ -195,23 +192,12 @@
     #
     rule empty ( )
     {
- if ! $(self.value)
+ if ! $(self.value)-is-defined
         {
             return true ;
         }
     }
 
- # Returns the list of all valid indices for this vector.
- #
- rule indices ( )
- {
- if ! [ empty ]
- {
- local size = [ size ] ;
- return [ range 1 : $(size) ] $(size) ;
- }
- }
-
     # Returns the textual representation of content.
     #
     rule str ( )
@@ -220,7 +206,6 @@
     }
 
     # Sorts the vector inplace, calling 'utility.less' for comparisons.
- # NOTE: this rule is unused at the moment.
     #
     rule sort ( )
     {
@@ -233,9 +218,10 @@
     rule equal ( another )
     {
         local mismatch ;
- if [ size ] = [ $(another).size ]
+ local size = [ size ] ;
+ if $(size) = [ $(another).size ]
         {
- for local i in [ indices ]
+ for local i in [ numbers.range 1 $(size) ]
             {
                 if ! [ utility.equal [ at $(i) ] [ $(another).at $(i) ] ]
                 {
@@ -262,12 +248,11 @@
     import "class" : new ;
 
     local v1 = [ new vector ] ;
+ assert.true $(v1).empty ;
     assert.result 0 : $(v1).size ;
- assert.result : $(v1).indices ;
     assert.result "[" "]" : $(v1).str ;
     $(v1).push-back b ;
     $(v1).push-front a ;
- assert.result 1 2 : $(v1).indices ;
     assert.result "[" a b "]" : $(v1).str ;
     assert.result a : $(v1).front ;
     assert.result b : $(v1).back ;
@@ -321,13 +306,16 @@
     assert.true $(v6).equal [ new vector [ new vector 1 2 3 ] ] ;
 
     local v7 = [ new vector 111 222 333 ] ;
+ assert.true $(v7).equal $(v7) ;
     $(v7).insert 4 : 444 ;
     assert.result 111 222 333 444 : $(v7).get ;
     $(v7).insert 999 : xxx ;
     assert.result 111 222 333 444 xxx : $(v7).get ;
 
     local v8 = [ new vector "" "" "" ] ;
+ assert.true $(v7).equal $(v7) ;
     assert.result 3 : $(v8).size ;
+ assert.false $(v8).empty ;
     $(v8).insert 2 : 222 ;
     assert.result 4 : $(v8).size ;
     assert.result "" 222 "" "" : $(v8).get ;
@@ -337,4 +325,10 @@
     $(v8).insert 999 : xxx ;
     assert.result 6 : $(v8).size ;
     assert.result "" 222 "" "" "" xxx : $(v8).get ;
+
+ # Regression test for a bug causing vector.equal to compare only the first
+ # and the last element in the given vectors.
+ local v9 = [ new vector 111 xxx 222 ] ;
+ local v10 = [ new vector 111 yyy 222 ] ;
+ assert.false $(v9).equal $(v10) ;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk