Boost logo

Boost :

Subject: Re: [boost] boost and vendor's TR1 implementations
From: Sergey Sadovnikov (flex_ferrum_at_[hidden])
Date: 2008-11-12 13:39:15


Hello, David.

Wednesday, November 12, 2008 at 8:14:55 PM you wrote:

DA> on Wed Nov 12 2008, Sergey Sadovnikov <flex_ferrum-AT-artberg.ru> wrote:

>> By the way when C++0x will be committed and std::tr1 namespace will be merged
>> with std namespace a lot of code will become uncompilable because of
>> both std and boost namespaces exposed into global or local scope.

DA> "Doctor, it hurts when I do this..."
:)

DA> Sorry to be glib, but I really can't get too worked up over this.
DA> This is why we have namespaces. If you erase the namespace boundaries,
DA> collisions happen. Should anyone be surprised that names in Boost, a
DA> library collection specifically aimed at standardization, eventually
DA> match some of those in std::?

Absolutely right, but...
Let's see an example. Just get the one of the boost test cases
(http://www.boost.org/doc/libs/1_37_0/libs/function/test/lambda_test.cpp)
and try to compile with gcc 4.3.2:

-----------------------------------------------------------------------
// Boost.Function library

// Copyright Douglas Gregor 2002-2003. Use, modification and
// distribution is subject to 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)

// For more information, see http://www.boost.org

#include <iostream>
#include <cstdlib>

#include <boost/test/minimal.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/function.hpp>

using namespace std;
using namespace boost;
using namespace boost::lambda;

static unsigned
func_impl(int arg1, bool arg2, double arg3)
{
  return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
}

int test_main(int, char*[])
{
  function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
  function <unsigned(double)> f2 = bind(f1, false, _1);
  function <unsigned()> f3 = bind(f2, 4.0);

  f3();

  return 0;
}
-----------------------------------------------------------------------

Compiler says:
P:\projects\Tests\Sandbox\C++0x\gcc43>g++ -std=c++0x -IP:\projects\common\boost_1.36.0 boost_test1.cpp
boost_test1.cpp: In function 'int test_main(int, char**)':
boost_test1.cpp:30: error: reference to 'function' is ambiguous
P:\projects\common\boost_1.36.0/boost/function/function_base.hpp:99: error: candidates are: template<class Signature> struct boost::function
s:\programming\mingw\bin\../lib/gcc/mingw32/4.3.2/include/c++/tr1_impl/functional:1464: error: template<class _Signature> struct std::function
boost_test1.cpp:30: error: functional cast expression list treated as compound expression
boost_test1.cpp:30: error: expected primary-expression before 'unsigned'
boost_test1.cpp:30: error: expected `;' before 'unsigned'
boost_test1.cpp:31: error: reference to 'function' is ambiguous
P:\projects\common\boost_1.36.0/boost/function/function_base.hpp:99: error: candidates are: template<class Signature> struct boost::function
s:\programming\mingw\bin\../lib/gcc/mingw32/4.3.2/include/c++/tr1_impl/functional:1464: error: template<class _Signature> struct std::function
boost_test1.cpp:31: error: expected primary-expression before 'unsigned'
boost_test1.cpp:31: error: expected `;' before 'unsigned'
boost_test1.cpp:32: error: reference to 'function' is ambiguous
P:\projects\common\boost_1.36.0/boost/function/function_base.hpp:99: error: candidates are: template<class Signature> struct boost::function
s:\programming\mingw\bin\../lib/gcc/mingw32/4.3.2/include/c++/tr1_impl/functional:1464: error: template<class _Signature> struct std::function
boost_test1.cpp:32: error: 'f3' was not declared in this scope
boost_test1.cpp:32: error: 'f2' was not declared in this scope

As you can see <tr1/functional> header isn't explicitly included but
compilation was failed.

I mean that code which is conform to the some boost examples or other
*same* guidelines which explicitly or implicitly expose both 'boost' and
'std' namespaces into global or local scope could become
automatically uncompilable...

-- 
Best Regards,
 Sergey                          mailto:flex_ferrum_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk