Boost logo

Boost Users :

Subject: Re: [Boost-users] previously working boost code breaks with c++0x
From: Christopher Jefferson (chris_at_[hidden])
Date: 2010-07-07 13:22:55

On 7 Jul 2010, at 18:15, Nathan Ridge wrote:

> Hello,
> The following code, which compiles just fine with g++ 4.4 without the --std=c++0x flag,
> gives an error with that flag:
> #include <string>
> #include <boost/tuple/tuple.hpp>
> #include <boost/algorithm/string.hpp>
> using boost::make_tuple;
> void f(int i, const std::string& s)
> {
> boost::tuple<int, std::string> t;
> t = make_tuple(i, s);
> }
> test.cpp: In function ‘void f(int, const std::string&)’:
> test.cpp:12: error: no match for ‘operator=’ in ‘t = std::make_tuple(_Elements&& ...) [with _Elements = int&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::string*)s)))’
> Note that any one of the following makes the code compile:
> 1) Removing the --std=c++0x flag
> 2) Removing the <boost/algorithm/string.hpp> include
> 3) Removing the using boost::make_tuple declaration and explciitly qualifying boost::make_tuple in f().
> What is going on?

The compiler is picking up std::make_tuple, because s is in the std:: namespace, so it looks for make_tuple in there first and finds it. This returns a std::tuple, which can't be converted to a boost::tuple. I assume that (somehow) <string> is picking up <tuple> in C++0x mode.

I have had similar issues, the only good consistent solution I came across is to make sure you do not use 'using' when accessing make_tuple and tuple. In the long term it might be nice if there was better co-operation between std::tuple and boost, but that is for future work.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at