Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2006-09-27 13:22:00


The BOOST_PARAMETER_KEYWORD(tag, name) macro expands, in part, to
something like:

keyword<tag::name> & name = ...;

Shouldn't this be:

keyword<tag::name> const & name = ...;
                    ^^^^^

What is the reason for using a non-const ref here? These things are not
mutable. In fact, it is causing me problems. Consider a placeholder type
with an implicit conversion operator:

struct default_constructed_t {
     template<typename T>
     operator T() const {
         return T();
     }
};

default_constructed_t const default_constructed = {};

BOOST_PARAMETER_KEYWORD(tag, value)

Now, when I do this: "value = default_constructed;" I get this error:

main.cpp:306: error: ISO C++ says that these are ambiguous, even though
the worst conversion for the first is better than the worst conversion
for the second:
/cygdrive/c/boost/consulting/svn/main/boost/1.33.1/backports/boost_1_33_1/boost/parameter/
keyword.hpp:59: note: candidate 1: const typename
boost::parameter::aux::tag<Tag, const T>::type
boost::parameter::keyword<T>::operator=(const T&) const [with T =
default_constructed_t, Tag = tag::value]
/cygdrive/c/boost/consulting/svn/main/boost/1.33.1/backports/boost_1_33_1/boost/parameter/
keyword.hpp:32: note: candidate 2:
boost::parameter::keyword<tag::value>&
boost::parameter::keyword<tag::value>::operator=(const
boost::parameter::keyword<tag::value>&)

Had the keyword object been const, the call would not have been ambiguous.

-- 
Eric Niebler
Boost Consulting
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