Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-06-30 06:55:14

"Peter Dimov" <pdimov_at_[hidden]> writes:

> David Abrahams wrote:
>> Michael Glassford <glassfordm_at_[hidden]> writes:
>>>> Also, going back to the struct technique, do the struct instances
>>>> need to be in an anonymous namespace to prevent ODR violations? Just
>>>> trying to get my head around the concept.
>>> Probably they should be in a separate namespace, though possibly not
>>> anonymous.
>> Anonymous namespaces in header files *cause* ODR violations. Not sure
>> how they can be used to prevent ODR violations.
>> Peter, are you planning to get the bind placeholders out of the
>> unnamed namespace?
> I'm not sure how the bind placeholders can cause ODR violations; could you
> elaborate?


  // f.hpp
  template <class S, class T>
  bool f(S const& s, T const& x)
     return std::find_if(
          s.begin(), s.end()
        , boost::bind(std::less<T>(), _1, x)) != s.end();

  // t1.cpp
  #include "f.hpp"
  #include <vector>
  bool f1(std::vector<int> const& s, int x) { return f(s,x); }

  // t2.cpp
  #include "f.hpp"
  #include <vector>
  bool f2(std::vector<int> const& s, int x) { return f(s,x); }

f<std::vector<int>,int> refers to a different object when it names
"_1" in each translation unit.

> Anyway, I guess we'll have to migrate to TR1 style placeholders one
> day, but this will break existing code.

I'm not sure it has to:

  namespace bind {
    extern arg<1> _1;
  namespace { // if you like
    using bind::_1;

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at