
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