enable_if< is_convertible > w/ explicit constructor trouble
After reading a recent Joel on Software article (
http://www.joelonsoftware.com/items/2003/10/13.html ) and the
discussion it generated, I decided to try to write some sort of
general strong typedef.
I've started out by creating a specific class similar to what would be
generated by a `typedef strong_typedef
"me22"
// But if I try this, I get the errors template <typename fT> explicit position(typename boost::enable_if< boost::is_convertible
, fT>::type f) : m_data( f ) {} */
Try:
template <typename fT>
explicit position(
fT f,
typename boost::enable_if<
boost::is_convertible
On 12/05/05, Andy Little
Try:
template <typename fT> explicit position( fT f, typename boost::enable_if< boost::is_convertible
, void* >::type = 0 ) : m_data( f ) {}
Thanks Andy, that worked perfectly. - Scott McMurray
me22 wrote:
After reading a recent Joel on Software article ( http://www.joelonsoftware.com/items/2003/10/13.html ) and the discussion it generated, I decided to try to write some sort of general strong typedef.
The article you linked to doesn't mention typedefs, it's about the alleged harmfulness of exceptions (and it seems poor Joel just didn't understand Resource Acquisition is Initialization in C++ or try-finally in Java/C#). Am I right to assume that with "strong typedef" you mean something like a typedef, but where each identifier defined in this way is an actual type and not just an alias? Best regards, Arne Vogel
On 13/05/05, Arne Vogel
The article you linked to doesn't mention typedefs, it's about the alleged harmfulness of exceptions (and it seems poor Joel just didn't understand Resource Acquisition is Initialization in C++ or try-finally in Java/C#).
As quite a number of people are mentioning in his forum =)
Am I right to assume that with "strong typedef" you mean something like a typedef, but where each identifier defined in this way is an actual type and not just an alias?
That's the idea, yes. The idea is to make it so that assigning an unsafe_string to a safe_string ( yes, the names are vague, but they're from the article ) either invalid or cause an applicable transformation function to be called so the resulting safe_string isn't unsafe, despite both being basically just a std::string I started a topic on Joel's forum about it that includes a preliminary, but working, version of the class and an ( oversimplified ) example use case. It's at http://discuss.joelonsoftware.com/default.asp?joel.3.126259.24 if you're interested. I'd also appreciate some design and/or implementation feedback if anyone does check it out. As mentioned, it's my first try at creating a sort of policy-based ( if that's the correct term ) class as well as my first time using boost's SFINAE tools. Regards, Scott McMurray
participants (3)
-
Andy Little
-
Arne Vogel
-
me22