How to check for implicit type conversion WITHOUT checking the source object's interface

I'm trying to find a way to see if a given object is convertible to std::string, but with certain restrictions. Normally, is_convertible<> would be fine, but in this case it doesn't work for my needs. Here's the situation in more detail. I've got a class Foo with a string conversion operator: class Foo { public: operator std::string () const; }; I want some kind of is_convertible<Foo, std::string> to return FALSE, but something like is_convertible<char*, std::string> to return TRUE. Basically, I want is_convertible to check to see if the target type (std::string) has an implicit constructor taking the input type; I *don't* want is_convertible to check to see if the input type has a conversion-to-target-type function. Is there a way to do this? --Steve

At 08:49 2005-06-15, Stephen Gross wrote:
I'm trying to find a way to see if a given object is convertible to std::string, but with certain restrictions. Normally, is_convertible<> would be fine, but in this case it doesn't work for my needs.
Here's the situation in more detail. I've got a class Foo with a string conversion operator:
class Foo { public: operator std::string () const; };
I want some kind of is_convertible<Foo, std::string> to return FALSE, but something like is_convertible<char*, std::string> to return TRUE. Basically, I want is_convertible to check to see if the target type (std::string) has an implicit constructor taking the input type; I *don't* want is_convertible to check to see if the input type has a conversion-to-target-type function.
the difference between them being? (I don't mean implementation here, I mean "meaning").
Is there a way to do this?
--Steve _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"

I'm trying to find a way to see if a given object is convertible to std::string, but with certain restrictions. Normally, is_convertible<> would be fine, but in this case it doesn't work for my needs.
Here's the situation in more detail. I've got a class Foo with a string conversion operator:
class Foo { public: operator std::string () const; };
I want some kind of is_convertible<Foo, std::string> to return FALSE, but something like is_convertible<char*, std::string> to return TRUE. Basically, I want is_convertible to check to see if the target type (std::string) has an implicit constructor taking the input type; I *don't* want is_convertible to check to see if the input type has a conversion-to-target-type function.
Is there a way to do this?
Yes, it's quite cunning and we use it to implement is_enum: a conversion sequence is only permitted one user defined conversion, so try: is_convertible<your_type, convertible_to_string> where convertible_to_string is a class with a constructor that accepts a string as a single argument. I think that will do it, I hope so anyway! John.
participants (3)
-
John Maddock
-
Stephen Gross
-
Victor A. Wagner Jr.