|
Boost : |
Subject: Re: [boost] iterator_facade triggers ADL, fails to compile
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-05-25 06:12:17
On 25/05/2011 11:58, Arno Schödl wrote:
> 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) \
> ); \
> }
An alternative could also have been to use boost::addressof
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk