|
Boost : |
From: Anton Gutsunaev (toto.lists_at_[hidden])
Date: 2004-11-21 07:54:04
Some examples in <boost>/libs/assign/doc/index.html file print "Assertion failed" message or cannot be compiled.
<boost>/libs/assign/doc/index.html#operator+=
vector<int> values;
values += 1,2,3,4,5,6,7,8,9; // insert values at the end of the container
BOOST_ASSERT( values.size() == 9 );
BOOST_ASSERT( values[0] == 1 );
BOOST_ASSERT( values[9] == 9 );// <---must be "values[8]"
<boost>/libs/assign/doc/index.html#operator()
map<string,int> months;
insert( months )
( "january", 31 )( "february", 28 )
( "march", 31 )( "april", 30 )
( "may", 31 )( "june", 30 )
( "july", 31 )( "august", 31 )
( "september", 30 )( "october", 31 )
( "november", 30 )( "december", 31 );
BOOST_ASSERT( m.size() == 12 ); //<---change "m" to "months"
BOOST_ASSERT( m["january"] == 31 ); //<---same here
after words "If operator()() is too cumbersome to use with eg. push_front()we can also say":
deque<int> di;
push_front( di ) = 1,2,3,4,5,6,7,8,9;
BOOST_ASSERT( di.size() == 9 );
BOOST_ASSERT( di[8] == 9 );//<-- must be di[8]==1 or di[0]==9 because of push_front
<boost>/libs/assign/doc/index.html#list_of:
const stack<string> names = list_of( "Mr. Foo" )( "Mr. Bar")( "Mrs. FooBar" ).to_adapter();
const stack<string> names2 = (list_of( "Mr. Foo" ), "Mr. Bar", "Mrs. FooBar" ).to_adapter();
BOOST_ASSERT( names.size() == 3 );
BOOST_ASSERT( names[0] == "Mr. Foo" ); //<---can't use operator [] with stack
BOOST_ASSERT( names[2] == "Mrs. FooBar" ); //<---same here
example after words "A more general list can be constructed with repeat_fun()":
template< class T >
struct next
{
T seed;
next( T seed ) : seed(seed)
{ }
T operator()() const //<---remove const or declare "T seed" as mutable
{
return seed++;
}
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk