Boost logo

Boost Users :

Subject: Re: [Boost-users] [Assign] Error using list_of() with Visual C++ 2010 Beta 1
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-09-30 05:01:15


2009/9/30 Paul Baker <paulbaker8_at_[hidden]>

> I've been discussing this issue with one of the Visual C++ developers;
> they believe that part of the problem is that "Boost[.Assign]'s code
> is ambiguous according to the [C++0x] Working Paper".
>
> Does anyone know whether this is, in fact, the case?

This is easy to believe, because I know for sure that direct-initialization
of vector from list_of is ambiguous under the rules of current C++ standard.
  #include <vector>
  #include <boost/assign/list_of.hpp>

  int main () {
    std::vector<int> v1(boost::assign::list_of(0)); // Ambiguous.
    std::vector<int> v1 = boost::assign::list_of(0); // OK.
  }

In case of direct-initialization, there are 3 constructors of std::vector
that can be used:
  vector(const vector&);
  explicit vector(size_t);
  explicit vector(const Allocator&);

In case of copy-initialization, only the first constructor can be used,
because the other two are explicit.

AFAIK, there is no easy way to change Boost.Assign to work around this
problem, because there is no way to use enable_if with conversion operator.
So solution is to use copy-initialization instead of direct-initialization.

Roman Perepelitsa.



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