Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2005-05-01 16:11:53


"Eric Zijlstra" <ezijlstra_at_[hidden]> wrote in message
news:d4un8k$tvr$1_at_sea.gmane.org...
|I was looking for a convinient way to have variabele arguments for functions
| and avoiding the memory allocations and copying that come with std
| containers. I didn't find such a container so I hacked one together myself.

| // usage example:
|
| void print(StackArg<const int> s) // outputs 345
| {
| StackArg<const int>::iterator i= s.begin(), e=end();
| while(i!=e) cout << *i++;
| }
|
| void test()
| {
| print( StackArg<const int>() + 3 + 4 +5 );
| }

boost.assign features a new function that does just this:

template< class Range >
 void print( const Range& s) // outputs 345
 {
    typename Range::iterator i= s.begin(), e=end();
    while(i!=e) cout << *i++;
 }

void test()
{
    print( boost::assign::cref_list_of<3>( 3 )( 4 )( 5 ) );
}

there is also ref_list_of<N>() if you need to pass non-const references. The
implementation uses an array of pointers and
is as fast as possible IMO.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk