Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users] [assign] std::vector initialisation by boost::assign::list_of
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2010-03-17 08:51:09


On Wed, Mar 17, 2010 at 1:32 PM, Andrey Torba <andreytorba_at_[hidden]> wrote:

> The code is compilable on msvc but is not on gcc-4.3:
>
> But the problem occurs when i try to initialise std::vector in a class
> initialization list:
> class sss
> {
> std::vector<int> v;
> sss()
> : v(boost::assign::list_of(1)(2))
> {}
> };
>
> What happens if you call:
sss()
    : v(boost::assign::list_of(1)(2).to_adapter())
  {}

list_of implements 2 members:
implicit conversion opertor to the container type and the to_adapter member.
You can cast list_of instance to your vector<int> if that with adapter does
not work. Other solution can be:

If you need efficiency, you still can use the vector ctor which reserves the
number of items in a vector and than copies
the elements from the list.

sss() : v(2)
{
  v = list_of...;
}

Regards,
Ovanes



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