previously working boost code breaks with c++0x
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
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
#include
using boost::make_tuple;
void f(int i, const std::string& s) { boost::tuple
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
&](((const std::basic_string &)((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
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. Chris
participants (2)
-
Christopher Jefferson
-
Nathan Ridge