name collision - llvm::tie and boost::tie

The BGL (Boost Graph Library) defines tie(), which is exactly what the
tie() defined in STLExtras.h.

The header files of GBL use boost::tie(), and other boost libraries
use boost::tie() too.

How to resolve the ambiguity for compiler?

I'm sorry, I'm not quite following: how does "llvm::tie" clash with the
name "boost::tie"? If there is code that includes both LLVM and Boost
header files, they should be using fully-qualified namespaces, and not
"using namespace llvm; using namespace boost;" .

Couldn't you state the explicit namespaces. So not using "using
namespace llvm" and instead prefix all calls with "llvm::"?

-bw

The header files in boost do not use fully-qualified tie(). I probably
should not modify them. But my .cpp file #include them.

I hope I could "using namespace" boost and llvm in .cpp file, because
it's tedious to use fully-qualified identifiers in boost and llvm
namespace.

Couldn't you state the explicit namespaces. So not using "using
namespace llvm" and instead prefix all calls with "llvm::"?

The header files in boost do not use fully-qualified tie(). I probably
should not modify them. But my .cpp file #include them.

That should be fine if they are in a namespace boost {}.

I hope I could "using namespace" boost and llvm in .cpp file, because
it's tedious to use fully-qualified identifiers in boost and llvm
namespace.

Add:

using boost::somethingyoucareabout;
using boost::somethingelseyoucareabout;
using namespace llvm;

Or whatever you prefer. This way you only import the symbols you want.

-Chris

In fact, I believe that

   using namespace llvm;
   using namespace boost;
   using boost::tie;

should resove the problem witout needed to explicitly nominate all boost names
you use. Except that this does not work on global scope, but only in
namespace:

   namespace Tzu_Chien_Chiu
   {
           using namespace llvm;
           using namespace boost;
           using boost::tie;

       void func() { // Use 'tie'. }
   }

You can see "The C++ programming language", section C.10 for details.

- Volodya

<SNIP>

Also, it might be an idea to exploit Koenig lookup if either `tie'
function is a free function and uses types from its own namespace.

If these definitions hold:

namespace foo {
   struct bar {};
   do_something(const bar&);
}

You can call do_something() without the namespace qualification due to
Koenig lookup.

(global namespace)
using foo::bar;
bar b;
do_something(b); // resolves to foo::do_something()

Maybe this helps.

Regards,
Andreas

This is getting off-topic for this list, but ADL (aka. Koenig lookup) won't
help with "tie", because 'tie' is mostly called on std::pair.

- Volodya

Tzu-Chien Chiu wrote:

I hope I could "using namespace" boost and llvm in .cpp file, because
it's tedious to use fully-qualified identifiers in boost and llvm
namespace.

How often do you need to mix the two libraries? Or specifically, use the two versions of tie() in the same cpp? A little #include discipline could go a long way in avoiding such clashes. LLVM source itself is a good example of how to avoid including headers unless absolutely necessary.

Or, simply qualify tie() in the appropriate places, while you continue to use the "using namespace" directive. The following code works for me:

#include <iostream>

namespace one {

   void arbit_one()
   {
     std::cout << "arbit one" << std::endl;
   }

   void name_space()
   {
     std::cout << "namespace one" << std::endl;
   }
}

namespace two {

   void arbit_two()
   {
     std::cout << "arbit two" << std::endl;
   }

   void name_space()
   {
     std::cout << "namespace two" << std::endl;
   }
}

int main()
{
   using namespace one;
   using namespace two;

   one::name_space();
   arbit_one();
   two::name_space();
   arbit_two();

   return 0;
}

Sameer.