Boost logo

Boost :

Subject: Re: [boost] [Review] Boost.Type Traits Extension by Frederic Bron
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2011-03-18 02:05:43


> I've found some problems. In the ICL I have an
> operator +
>
> template <class Type>
> inline typename enable_if
> <is_associative_element_container<Type>, Type>::type
> operator + (Type object, const Type& operand);
>
> and is seems that more overloads are checked valid as actually exist.
> Is this intentional?
>
> BOOST_AUTO_TEST_CASE(has_op_extension_qualifiers)
> {
> typedef int T;
> typedef interval_set<T>             IntervalSetT;
> typedef IntervalSetT::interval_type IntervalT;
>
> // This is supposed to succeed
> BOOST_CHECK((has_operator_plus<IntervalSetT, const IntervalSetT&,
> IntervalSetT>::value));
>
> BOOST_CHECK((!is_convertible<const IntervalSetT&, IntervalSetT&>::value));
>
> // These are supposed to fail, but they succeed
> BOOST_CHECK((has_operator_plus<IntervalSetT, IntervalSetT&,
> IntervalSetT>::value));
> BOOST_CHECK((has_operator_plus<IntervalSetT, IntervalSetT,
> IntervalSetT>::value));
> BOOST_CHECK((has_operator_plus<IntervalSetT, IntervalSetT,
> IntervalSetT const&>::value));
> }

Your question here is the same as the following example:

struct T { };
struct RET { };

RET f(T, const T&) { return RET(); }
void g(RET) { }
void h(const RET&) { }

int main() {
        //Does this work?
        { T t1; const T &t2=t1; g(f(t1, t2)); } // -> yes
        { T t1; T &t2=t1; g(f(t1, t2)); } // -> yes
        { T t1; T t2; g(f(t1, t2)); } // -> yes
        { T t1; T t2; h(f(t1, t2)); } // -> yes
        return 0;
}

What it means it that has_operator_plus<LHS, RHS, RET> does not check
for exact conformance of arguments LHS and RHS but checks if you can
use LHS and RHS as arguments to the operator. And clearly you can use
a lot of types when your operator is declared taking a const RHS&.
Hope this helps. I think this policy is desirable otherwise you would
have to test many options, especially with binary operators before
being sure you can use the operator.
Frédéric


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