Best method of checking for ==, <, streamability

A user recently posted on boost-users asking for operator== support in boost::any. I have added this support to my private version, which extends spirit's implementation of any. I am interested in cleaning this up and submitting it to replace boost::any, if everyone is happy with this. The major issue is that my implementation requires type support operator==, operator< , hash and operator<< / operator>>. Are there any techniques in boost for detecting the presence of these operators which are sufficiently reliable they could be used in boost::any? Apologises for this question, but I have lost track of how well such checks can be implemented. Thanks, Christopher Jefferson

On 01/11/10 18:15, Christopher Jefferson wrote:
A user recently posted on boost-users asking for operator== support in boost::any. I have added this support to my private version, which extends spirit's implementation of any. I am interested in cleaning this up and submitting it to replace boost::any, if everyone is happy with this.
The major issue is that my implementation requires type support operator==, operator< , hash and operator<< / operator>>. Are there any techniques in boost for detecting the presence of these operators which are sufficiently reliable they could be used in boost::any?
Apologises for this question, but I have lost track of how well such checks can be implemented.
Thanks,
Christopher Jefferson
It can be doen using the sizeof trick by trying to take the size of a return type of an overloaded function depending on the very existence of say function. IIRC, such stuff where done for arithmetic tests and proposed for inclusion into type_traits. You can aslo see hwo to do them here: http://github.com/jfalcou/boosties/blob/master/introspection/boost/has_membe... This is the usual way to check for memebr function. Same applies to regular functions by changing the type of the pointer you want to take and how to test them.

On 1 November 2010 12:15, Christopher Jefferson <chris@bubblescope.net> wrote:
A user recently posted on boost-users asking for operator== support in boost::any. I have added this support to my private version, which extends spirit's implementation of any. I am interested in cleaning this up and submitting it to replace boost::any, if everyone is happy with this.
It depends on what its semantics are. I can get the functionality that user posted by externally comparing the addresses of the boost::any objects, so it isn't very useful. Semantics that are, say: 1. Not equal of they are different types of objects. 2. Use they expression l == r if they are the same type of object. 3. Throw if l == r is ill-formed. Would be useful.
The major issue is that my implementation requires type support operator==, operator< , hash and operator<< / operator>>. Are there any techniques in boost for detecting the presence of these operators which are sufficiently reliable they could be used in boost::any?
As part of my BoostCon '10 talk on Type Erasure, I implemented the stream insertion operator for boost::any (as an example, not a proposal). Slides are at <http://www.filetolink.com/850e7c00>. My is_ostreamable type trait is based on the implementation of is_incrementable found in boost/detail/is_incrementable.hpp. (If you want me to send it to you contact me off-list.) What I'd like to see is more of these type traits: is_ostreamable, is_equality_comparable, etc. I'm willing to contribute the first one. :-) -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404

On 11/1/2010 10:15 AM, Christopher Jefferson wrote:
A user recently posted on boost-users asking for operator== support in boost::any. I have added this support to my private version, which extends spirit's implementation of any. I am interested in cleaning this up and submitting it to replace boost::any, if everyone is happy with this.
The major issue is that my implementation requires type support operator==, operator< , hash and operator<< / operator>>. Are there any techniques in boost for detecting the presence of these operators which are sufficiently reliable they could be used in boost::any?
Apologises for this question, but I have lost track of how well such checks can be implemented.
Thanks,
Christopher Jefferson _______________________________________________ Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
If you're thinking of submitting a potential replacement for boost::any, could you maybe add support for custom allocators as well? :)

On 01/11/10 17:15, Christopher Jefferson wrote:
A user recently posted on boost-users asking for operator== support in boost::any. I have added this support to my private version, which extends spirit's implementation of any. I am interested in cleaning this up and submitting it to replace boost::any, if everyone is happy with this.
I wonder what happened to http://cpp-experiment.sourceforge.net/boost/libs/dynamic_any/doc/tutorial.ht...
The major issue is that my implementation requires type support operator==, operator< , hash and operator<< / operator>>. Are there any techniques in boost for detecting the presence of these operators which are sufficiently reliable they could be used in boost::any?
You may like to take a look at boost/detail/is_incrementable.hpp -- Max
participants (5)
-
Christopher Jefferson
-
joel falcou
-
Maxim Yegorushkin
-
Nevin Liber
-
new.gmane.org