Boost logo

Boost :

Subject: Re: [boost] review request: addition to type_traits library of has_operator_xxx
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2010-12-09 15:18:51


I made some progress in the implementation of operator traits.

1. as John was not in favor of the namepace option, I sticked to
has_operator_xxx naming convention.
2. I have already added the following operators (in the sandbox): +=,
*=, -=, /*, %=, &=, |=, ^=, <<, >>, >>=, <<=
3. I have tried to use the existing is_convertible traits but without
any success:
The problem is that is_convertible expect a type as parameter, not an
expression. So I have tried to get the return type of the operator
with:
a) boost result_of (but this does not work for arbitrary expression),
b)boost typeof (but types must be registered first)
c) with the following code:

#include <iostream>
#include <boost/type_traits/is_convertible.hpp>

template <class To, class From>
bool is_conv(const From&) { return boost::is_convertible< From, To >::value; };

struct tag { };

int main() {
        std::cout<<is_conv<bool>(1+2)<<'\n';
        std::cout<<is_conv<tag>(1+2)<<'\n';
        return 0;
}

but if I use is_conv(1+2) to set a value variable of type bool in the
traits, the compiler complains that "is_conv(1+2)" is not a constant
expression...

So my questions:
1. is there an easy way to get the type of an expression and to pass
it to is_convertible
2. if not, why not just using the working code I wrote already?

Regards,

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