Re: [Boost-users] boost 1.37, tr1 and gcc 4.x

Hello, Acsoft. Tuesday, November 11, 2008 at 6:24:51 PM you wrote:
Hello, I am using boost 1.37 and gcc 4.3.2. I am getting a very nasty error when I mix up boost headers and tr1 > headers in one compilation unit.
Some time ago I encountered the same problem with VS 2008 SP1 and shared_ptr. Solution which I found was not to expose boost namespace into global namespace. This is ugly but works. -- Best Regards, Sergey mailto:ssadovnikov@egopolis.com

2008/11/11 Sergey Sadovnikov
Hello, Acsoft.
Tuesday, November 11, 2008 at 6:24:51 PM you wrote:
Hello, I am using boost 1.37 and gcc 4.3.2. I am getting a very nasty error when I mix up boost headers and tr1 > headers in one compilation unit.
Some time ago I encountered the same problem with VS 2008 SP1 and shared_ptr. Solution which I found was not to expose boost namespace into global namespace. This is ugly but works.
-- Best Regards, Sergey mailto:ssadovnikov@egopolis.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I would say that is not ugly but good practice ie "do not pollute the global namespace"

Hello, liam.
Tuesday, November 11, 2008 at 6:53:28 PM you wrote:
lm> I would say that is not ugly but good practice ie "do not pollute the
lm> global namespace"
Ok. Let's take the boost example:
http://www.boost.org/doc/libs/1_37_0/libs/bind/bind_as_compose.cpp
, try to compile it with some modifications:
#include

Either way, as soon as people start to use c++0x compiler and c++0x-conform stl implementations (in fact a lot of people already do - like me), all the old code that uses using namespace std and using namespace boost will fail to compile (the tr1 stuff is merged into std in c++0x - and a lot of these old tr1 libraries are included indirectly by other stl headers!).
As boost and the stl are fundamental libraries, they should, in my opinion, coexist in the global namespace.
I think the boost implementations should move the std::tr1 implementation into the boost namespace if possible. This should solve all the problems.
example:
array.hpp
#ifdef STL_ARRAY_EXISTS
# ifdef USE_TR1
# include
Hello, liam.
Tuesday, November 11, 2008 at 6:53:28 PM you wrote:
lm> I would say that is not ugly but good practice ie "do not pollute the lm> global namespace"
Ok. Let's take the boost example: http://www.boost.org/doc/libs/1_37_0/libs/bind/bind_as_compose.cpp , try to compile it with some modifications:
#include
#if defined(BOOST_MSVC) #pragma warning(disable: 4786) // identifier truncated in debug info #pragma warning(disable: 4710) // function not inlined #pragma warning(disable: 4711) // function selected for automatic inline expansion #pragma warning(disable: 4514) // unreferenced inline removed #endif
// // bind_as_compose.cpp - function composition using bind.hpp // // Version 1.00.0001 (2001-08-30) // // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //
#include
#include <iostream> #include <string> #include #include std::string f(std::string const & x) { return "f(" + x + ")"; }
std::string g(std::string const & x) { return "g(" + x + ")"; }
std::string h(std::string const & x, std::string const & y) { return "h(" + x + ", " + y + ")"; }
std::string k() { return "k()"; }
template<class F> void test(F f) { std::cout << f("x", "y") << '\n'; }
int main() { using namespace boost; using namespace std; using namespace tr1;
function
foo; // compose_f_gx
test( bind(f, bind(g, _1)) );
// compose_f_hxy
test( bind(f, bind(h, _1, _2)) );
// compose_h_fx_gx
test( bind(h, bind(f, _1), bind(g, _1)) );
// compose_h_fx_gy
test( bind(h, bind(f, _1), bind(g, _2)) );
// compose_f_k
test( bind(f, bind(k)) );
return 0; }
and face out following errors: g++ -std=c++0x -IP:\projects\common\boost_1.36.0 boost_test.cpp boost_test.cpp: In function 'int main()': boost_test.cpp:60: error: reference to 'function' is ambiguous cc1plus.exe: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error> P:\projects\common\boost_1.36.0/boost/function/function_base.hpp:99: error: template<class Signature> struct boost::function boost_test.cpp:60: error: 'foo' was not declared in this scope
Compiler is gcc 4.3.x.
As you can see: 1. Global namespace was not polluted. Namespaces exposed only into the 'main' function scope. 2. Code is fully conform to the boost documentation.
-- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

ACSoft wrote:
I think the boost implementations should move the std::tr1 implementation into the boost namespace if possible. This should solve all the problems.
example:
array.hpp
#ifdef STL_ARRAY_EXISTS # ifdef USE_TR1 # include
# else # include <array> # endif #endif namespace boost { #ifdef STL_ARRAY_EXISTS # ifdef USE_TR1 using std::tr1::array; # else using std::array; # endif #else template<...> class array { //... }; #endif }
What do you think of this idea?
Personally I'm violently opposed for the reasons I gave in a previous mail. Sorry, John.
participants (4)
-
ACSoft
-
John Maddock
-
liam mail
-
Sergey Sadovnikov