Boost logo

Boost Users :

Subject: Re: [Boost-users] boost 1.37, tr1 and gcc 4.x
From: ACSoft (ac_soft_at_[hidden])
Date: 2008-11-11 16:50:10


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 <tr1/array>
# 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?

On Tue, 11 Nov 2008 19:38:46 +0300
Sergey Sadovnikov <flex_ferrum_at_[hidden]> wrote:

> 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 <boost/config.hpp>
>
> #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 <tr1/functional>
> #include <iostream>
> #include <string>
> #include <boost/bind.hpp>
> #include <boost/function.hpp>
>
> 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<void()> 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_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net