Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Assign] list_of::range without an initial (single) element?
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-06-17 07:53:39


Michael McNeil Forbes skrev:
> Thorsten Ottosen wrote:

>> Just to be clear, you want list_of() to be empty_list_of<*any
>> type*>(), and for the type of the list to be deduced by the first
>> argument:
>>
>> list_of()(42);
>>
>> would be a list of ints with one value (42).
>
> This is what I was expecting when I first started. Semantically this
> behaviour seems to make sense, but I have not thought too deeply about it.
>
>> If so, I think this syntax is possible, but I am worried that the
>> difference between list_of() and list_of<T>() is too subtle.
>
> What exactly would be the subtle difference between these two? Would
> they not both be forms of empty lists, except the second form would only
> accept arguments of type T?

Currently list_of<int>() is not an empty list.

> The other thing I was expecting was perhaps an exposed range() function
> so that one can just go:
>
> ... = range(a).range(b)
>
> (I also thought that the exposed repeat() functions would also allow for
> this:
>
> boost::array<int, 4> c = boost::assign::repeat(4, 5);
>
> use but I apparently do not understand yet how the exposed repeat is
> intended to be used.)

array has a fill member for that purpose, albeit it lacks a constructor.
No, repeat() and range() are used inside lists:

push_back( vec ) += 1,2,3,repeat(4,5),range(other_rng),5,6,7;

> I have to look more deeply into the new proposal for operator&&(), but
> it seems a little specific. Is there no way that the ideas discussed
> here could be made as efficient, requiring a separate operator&&() for
> chaining? As a user, I would not mind being steered towards the
> efficient usage if documented properly.

The new methods are quite efficient. In the old library, list_of<T>() is
not efficient (ease of use is the key goal here), whereas
ref_list_of<T>()/cref_list_of() are.

-Thorsten

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net