[Boost-users] [Assign] Error using list_of() with Visual C++ 2010 Beta 1

79 views
Skip to first unread message

Paul Baker

unread,
Sep 3, 2009, 3:37:47 PM9/3/09
to boost...@lists.boost.org
In the Boost.Assign documentation, the following example of list_of() is given:

const list<int> primes = list_of(2)(3)(5)(7)(11);

However, I have tended to write this instead:

const list<int> primes(list_of(2)(3)(5)(7)(11));

This is causing problems with the Microsoft Visual C++ 2010 Beta 1
compiler. Using Visual C++ 2008, both lines compile fine but with 2010
Beta 1, the second produces the following error:

error C2668: 'std::list<_Ty>::list' : ambiguous call to overloaded
function with [_Ty=int]
could be 'std::list<_Ty>::list(std::list<_Ty> &&)' with [_Ty=int]
or       'std::list<_Ty>::list(unsigned int)' with [_Ty=int]
while trying to match the argument list
'(boost::assign_detail::generic_list<T>)' with [T=int]

Is this:

a) My fault? Should I be using copy initialization rather than
direct initialization?
b) A problem with the 2010 beta compiler?
or c) A problem with Boost.Assign?

Thanks
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thorsten Ottosen

unread,
Sep 8, 2009, 5:13:09 AM9/8/09
to boost...@lists.boost.org
Paul Baker skrev:

> In the Boost.Assign documentation, the following example of list_of() is given:
>
> const list<int> primes = list_of(2)(3)(5)(7)(11);
>
> However, I have tended to write this instead:
>
> const list<int> primes(list_of(2)(3)(5)(7)(11));
>
> This is causing problems with the Microsoft Visual C++ 2010 Beta 1
> compiler. Using Visual C++ 2008, both lines compile fine but with 2010
> Beta 1, the second produces the following error:
>
> error C2668: 'std::list<_Ty>::list' : ambiguous call to overloaded
> function with [_Ty=int]
> could be 'std::list<_Ty>::list(std::list<_Ty> &&)' with [_Ty=int]
> or 'std::list<_Ty>::list(unsigned int)' with [_Ty=int]
> while trying to match the argument list
> '(boost::assign_detail::generic_list<T>)' with [T=int]
>
> Is this:
>
> a) My fault? Should I be using copy initialization rather than
> direct initialization?

Well, if it works more portably, then why not.

> b) A problem with the 2010 beta compiler?

I really don't know. Try to ask a question on some newsgroup with some
C++ gurus.

> or c) A problem with Boost.Assign?

Well, I think Boost.Assign does everything it can.

-Thorsten

Paul Baker

unread,
Sep 29, 2009, 8:56:00 PM9/29/09
to boost...@lists.boost.org
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?

Roman Perepelitsa

unread,
Sep 30, 2009, 5:01:15 AM9/30/09
to boost...@lists.boost.org
2009/9/30 Paul Baker <paulb...@gmail.com>

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.
Reply all
Reply to author
Forward
0 new messages