Boost logo

Boost :

Subject: Re: [boost] review request: addition to type_traits library of is_less_comparable<T, U> and others
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2009-12-08 17:32:32


I have found another issue with these traits: it will not be possible
to treat all combinations of built-in types that do not work with
operators.
Example: 1. % 1. is not allowed by the standard and cannot be
redefined. Even the trick of an "any" class does not work. See below.
There is still the possibility to specialize the traits for all
built-in non working combinations...
Frédéric

#include <iostream>

template <class T> struct any { any(const T&) { }; };

template <class T>
double operator % (any<T> x, any<T> y) {
        std::cout << "my operator %\n" ;
        return 0.;
}

int main() {
        double x=1.;
        x=x%x; // compile time error -> error: invalid operands of
types double and double to binary operator%
        x=any<double>(x)%any<double>(x);
        return 0.;
}


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