1

Given the following class:

struct foo : public boost::static_visitor<> {
    void do_stuff(int item) {}
}

Now, in another context I have an std::vector<foo> and want to execute the following algorithm on it:

using namespace std::tr1;
using namespace std::tr1::placeholders;

std::vector<foo> items;
std::for_each(items.begin(), items.end(), bind(&foo::do_stuff, _1));

This throws a huge template error message, that boils down to an ambiguous call to std::tr1::ref or boost::ref. If I remove the base-class boost::static_visitor from foo everything works fine.

As far as I understand it, the problem is that deep down in the code of std::tr1::bind, a ref(arg) is called without namespace qualification. Because bind is in the namespace std::tr1, std::tr1::ref is in scope. But, because foo inherits from a class that is in the namespace boost, ADL also finds boost::ref. Is that understanding correct?

Since I need that base-class (it is part of Boost.Variant), I need to know if tis here any way to disambiguate this call from my code?

Note: I am stuck with C++03 here, hence the use of std::tr1.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
  • 1
    I think the [answer to this question](http://stackoverflow.com/questions/20546860/confusion-between-stdtr1ref-and-boostref) is a similar problem, you will need to open up the `boost` or `std::tr1` namespace and provide a special overload it seems. – Jesse Good Feb 02 '14 at 00:32

1 Answers1

0

Jesse has provided a link to an answer that is a solution to this problem. However, in this particular case, I have come up with a different solution. boost::static_visitor only has one function, it provides a result_type typedef. This can easily be added manually, and the the base-class is not needed anymore.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283