Boost logo

Boost :

From: Dave Abrahams (dave_at_[hidden])
Date: 2003-02-07 05:02:04


On Friday, February 07, 2003 4:54 AM [GMT+1=CET],
Vladimir Prus <ghost_at_[hidden]> wrote:

> Hi,
> I've just tried to use the header named above, from boost sandbox.
However,
> there's a serious problem with it. It includes another one, which
> declares find_if algorithm in namespace boost, and that causes ambiguity
> with std::find_if. The following code piece illustrates it
>
> #include <algorithm>
> #include <vector>
>
> namespace boost {
>
> struct truth_teller {
> template<class T>
> bool operator()(const T&) { return true; }
> };
>
> template <typename Iterator, typename Predicate>
> Iterator find_if(Iterator first, Iterator last, Predicate pred) {
> }
>
> void do_the_thing(std::vector<int>& t) {
> std::remove_if(t.begin(), t.end(), truth_teller());
> }
> }
>
> The situation is that implementation of std::remove_if calls find_if
> (not std::find_if). Thanks to argument-dependent lookup (the predicate
> is from boost namespace), boost::find_if is found, and ambiguity arises.
> (This all happens with g++ 3.2).
>
> So, what is it? A bug in standard library? A problem with the standard?

Many of us think it is both. Some people <ahem> on the GCC team have been
reluctant to fix it until they got a firm declaration from the LWG that it
was a bug, and now they are about to:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#229

> Or, providing another find_if in namespace boost can never work?

Not with GCC-3.2! Welcome to the wonderful world of ADL!

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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