Actually I tested some of them with gcc and the only solution I came up to resolve ambiguity is:


#include <boost/assign.hpp>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>


using namespace std;
using namespace boost;
using namespace boost::assign;



int main(int argc, char* argv[])
{
  typedef vector<int> int_vec;
  int_vec v = list_of(1)(2);
  int_vec v2(2);
  v2=list_of(1)(2).to_container(v2);

  ostream_iterator<int> oiter(cout, ",");
  copy(v2.begin(), v2.end(), oiter);
}

Hope that helps,

Ovanes



On Wed, Mar 17, 2010 at 1:52 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:
Sorry, it must be to_container() and not to_adapter().


On Wed, Mar 17, 2010 at 1:51 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:

On Wed, Mar 17, 2010 at 1:32 PM, Andrey Torba <andreytorba@gmail.com> 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