Boost logo

Boost :

Subject: [boost] iterator_facade triggers ADL, fails to compile
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2011-05-25 05:58:53


Hello,

the attached file arg_names.cpp fails to compile (VS2008) when using boost::lambda::_1 or boost::phoenix::arg_names::_1. The compilation succeeds when using boost::bind. All three variations are in the attached code for illustration.

The compilation fails due to the presence of a templated operator& definition which is introduced by the instantiation of a class that is declared "andable" (from boost/operators.hpp).

The compilation fails because iterator_facade triggers ADL in BOOST_ITERATOR_FACADE_INTEROP and finds the aforementioned operator& when comparing iterators that carry boost::lambda::_1 or boost::phoenix::arg_names::_1 as part of their type specification. In the example, this is illustrated by using filter_iterator.

It is not clear to me what exactly the mechanism is that causes this ADL problem. But the static_cast in BOOST_ITERATOR_FACADE_INTEROP can be implemented using references instead of pointers, as shown below, which makes the problem disappear. In any case, using operator& on the iterator may be problematic if the iterator overloads operator&.
 
--- C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/boost_1_46_1/boost/iterator/iterator_facade.hpp Wed May 25 11:42:14 2011
+++ C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/boost_1_46_1/boost/iterator/iterator_facade - Copy.hpp Wed May 25 11:41:49 2011
@@ -819,8 +819,8 @@
           is_interoperable< Derived1, Derived2 >::value \
       )); \
       return_prefix iterator_core_access::base_op( \
- *static_cast<Derived1 const*>(&lhs) \
- , *static_cast<Derived2 const*>(&rhs) \
+ static_cast<Derived1 const&>(lhs) \
+ , static_cast<Derived2 const&>(rhs) \
         , BOOST_ITERATOR_CONVERTIBLE(Derived2,Derived1) \
       ); \
   }

Does anyone understand better what is happening? Or can we simply adopt the change?

Regards,

Arno

--
Dr. Arno Schödl | aschoedl_at_[hidden]
Technical Director
think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091
Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl



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