Boost logo

Boost :

Subject: Re: [boost] [review][assign] Formal review of Assign v2 ongoing
From: er (er.ci.2020_at_[hidden])
Date: 2011-06-21 17:05:58


> About your other comments:
> - operator| has a similar meaning in Boost.Range under adaptors.
> - Feel free to suggest another prefix than 'do'.
> - Dot is borrowed from Boost.Assign (1.0).

Did you mean dot or %? The dot is a small price to pay for alternating
between various ways to insert elements in a container, within one
statement:

put( cont )( x, y, z ).for_each( range1 )( a, b ).for_each( range2 );

The answer to "[Is it] just a quest to type less when using standard
containers?" is yes, as illustrated just above, but it is quite a broad
definition of standard containers. Version 2.0 provides macros to
broaden it further (which was used to support Boost.MultiArray, for
example).

As for why such a library should exist, it depends on the degree to
which you value the syntax above, which is very similar to Boost.Assign
(1.0), in this case.

You say "I ordinarily only initialize containers to literals when
writing unit tests.". In this case, I think you are right that you can't
beat C++0x initializer lists. But, you still may need to fill a
container, as above. And also, consider the cases below:

#include <vector>
#include <queue>
#include <string>
#include <tuple>
#include <boost/assign/v2/include/csv_deque_ext.hpp>

int main()
{
     typedef std::string s_;
     {
         typedef std::tuple<s_, int> t_;
         typedef std::vector<t_> v_;
         v_ v1 = {
             t_( "a", 1 ),
             t_( "b", 2 ),
             t_( "c", 3 ),
             t_( "d", 4 ),
             t_( "e", 5 )
         };
         using namespace boost::assign::v2;
         v_ v2 = converter(
             csv_deque<t_, 2>( "a", 1, "b", 2, "c", 3, "d", 4, "e", 5)
         );
     }
     {
         typedef std::queue<int> q_;
        // Not aware that an initializer list works here
         using namespace boost::assign::v2;
         q_ q = converter(
             csv_deque<int, 1>( 1, 2, 3, 4, 5 )
         );
     }
     return 0;
}

> - Prefix _ is reserved for const objects (not sure the proper word
for it)

And I think this convention appears elsewhere in Boost, such as
Boost.Parameter.


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