Boost logo

Boost :

Subject: Re: [boost] [review][assign] Formal review of Assign v2 ongoing
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2011-06-21 16:47:10

John Bytheway wrote:
> On 20/06/11 18:36, Simonson, Lucanus J wrote:
> <snip>
>> I very much like initializer list syntax, but the syntax for this
>> library doesn't give me any warm feelings. Perhaps we need
>> motivating examples and a little bit of rationale for *why* such a
>> library should exist. Does it make doing something much easier in a
>> templated context or is it just a quest to type less when using
>> standard containers in code that looks like the examples? I
>> ordinarily only initialize containers to literals when writing unit
>> tests.
> I think unit tests are indeed an important use case for such a
> library. That's where I use the existing Boost.Assign.

In unit tests I tend to write ugly code like:

std::vector<Point> pts;
Polygon pgn(pts.begin(), pts.end());
assert(boost::polygon::area(pgn) == 100);

only because I'm lazy and I'm not really concerned about whether my unit test code is elegant. Unit tests is where I need such a library most, but care least.

I don't understand the motivation for having this library if using C++0x initializer lists is an option. What then is the point of C++0x only library features? Allowing a filter function to be applied on each element as it initializes the container seems somewhat of a stretch.

We can't have

template <typename T>
boost::range<T> get_range(T*, std::size_t size);

foo(get_range({"a", "b", "c"}, 3);

or even

template<typename T, int size>
boost:range<T> get_range(T[size]);

foo(get_range({"a", "b", "c"});

as a simple range adaptor for C-style array so that we can use regular array initializer lists as a range, but have to go through an intermediate c-sytle array instead.

I get this error:
test.cpp:6: error: expected primary-expression before '{' token
when I try, so I guess we can't pass C++98 initializer lists directly into functions. Even if we could that would only get us half way since we still wouldn't have initializer lists for elements of the array.

Oh well,

Boost list run by bdawes at, gregod at, cpdaniel at, john at