Boost logo

Boost :

Subject: [boost] Assign V2 - first impression
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2011-06-22 10:56:06


Hi all,

I've been using assign v1 for a long time, and I find it sometimes
convenient to have at hand but I don't consider it a crucial tool.
To have a v2 of the same library is to me..surprising.:)

Very well, I compared the introduction of v1 and v2 to get a feeling for the
difference

V1:

> The purpose of this library is to make it easy to fill containers with data
> by overloading operator,() and operator()(). These two operators make it
> possible to construct lists of values that are then copied into a container:

A parenthesis-separated list:
> map<string,int> m;
> insert( m )( "Bar", 1 )( "Foo", 2 );

V2:

> This second version of Boost.Assign is a new design, with optional support
> for C++0x. Its core utility is a compact interface for executing the
> repetitive tasks of assigning or inserting elements in a container, such as
> follows
> boost::for_each(
> cal | do_csv_put<2>( "jan", 31, "feb", 28, "mar", 31 ),
> std::cout
> << lambda::bind( &p_::first, lambda::_1 ) << ':'
> << lambda::bind( &p_::second, lambda:: _1 ) << ' '
> ); // prints jan:31 feb:28 mar:31

To my taste, I prefer V1
insert( m )( "Bar", 1 )( "Foo", 2 );

over V2
m | do_csv_put<2>( "Bar", 1, "Foo", 2)

Even if I would find V2's syntax to be more tasty to the eye, i don't see
that motivating enough for a new library at this point.

Very well, continuing to understand the V2 library..

This example captures the basic features of this library:

It maps arguments to a suitable data-element, p_( k, x ), and invokes a
> container's modifier, insert. These semantics vary by container category.

Operator | returns the modified container, thereby facilitating integration
> with range algorithms. There is a function, csv_put, that achieves the same
> as above, but without returning the container.

Why is operator | used at all, if there are two separate functions? It
doesn't look compelling to me and I'm perfectly fine with separating my
statements, one for the assign part and one for the for_each part. In fact,
the first example from the documentation would benefit from doing that,
since it would be much more readable.

cal | do_csv_put<2>( "jan", 31, "feb", 28, "mar", 31 );
boost::for_each(cal, long-lambda-expression..)

Now it looks even more odd with the operator |.

Additional features include:
> Options for overriding default semantics, and macros to create custom
> options
>
What are the default semantics?

> A functor analogue of csv_put, put, for constructing a sequence of elements
> from variadic argument lists
> Two functions, csv_deque<> and deque<>, which are the analogues of those
> just described, but which generate a container.

You lost me here. I needed to read those sentences a few time before I think
I understand what you mean.

Functionality that is adjunct to or independent of what precedes is itemized
> below:
>
Surely, this can be written smoother, no? =)

> Chaining ranges, with special consideration for those created using the ref
> functionalty (below)
>
I don't know what the docs are talking about at this point. Chaining ranges
in the assign library? That sounds to the uneducated mind like a job for
boost.range

> Conversion from ranges to containers
>
This sentence doesn't make sence to me. std::container(range.begin(),
range.end()) is supported by all containers.

> A framework, whose identifiers are in namespace ref, for generating an
> array of reference wrappers, for short, a reference-array.
>
I do not understand this part. What kind of container are we attempting to
populate here?

> Functionality is defined in namespace boost::assign::v2, thereby avoiding
> any clash with the prior version [1].

Ok.

Maybe V2 could show a compelling use-case that V1 lacks?
I get the feeling V2 shows features I don't understand how to use, or didn't
knew that I needed.

Cheers,
- christian


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