
Krzysztof Czainski wrote
What about this example:
struct Circ { unsigned x; explicit Circ(unsigned i=0) : x(i%256) {} }; bool operator<(Circ a, Circ b) { return (b.x-a.x)%256 < (a.x-b.x)%256; }
Is std::set <Circ> valid?
I think generally not, but... suppose that we know, that we're only going to use values 0-127. In this case std::set <Circ> is valid.
it won't trap at compile time. Of course depending upon the value of x it might not be valid at runtime - but "type requirements" don't pretend to address that. Type requirements specify what types are permitted at for template parameters - no more no less. It can't guarantee that any particular instance is "valid" (whatever that might mean). Runtime checking is a job of "pre-conditions" and assert. But if you want - you "could" go a little overboard and use template<int X> struct Circ { static unsigned x = X; }; bool operator<(Circ a, Circ b) { return (b.x-a.x)%256 < (a.x-b.x)%256; } Of course this is outside the scope of "type requirements" but it's still interesting. Robert Ramey -- View this message in context: http://boost.2283326.n4.nabble.com/Concepts-Definition-Was-GSoC-Boost-Hana-F... Sent from the Boost - Dev mailing list archive at Nabble.com.