Boost logo

Boost Users :

From: me22 (me22.ca_at_[hidden])
Date: 2005-05-12 09:42:42


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<tag,wrapped_type> name;`, and
am trying to use enable_if and is_convertible to allow explicit
construction from any type that can be converted to the wrapped type.
Unfortunately, I keep getting errors such as the following:
main.cpp:36: error: no matching function for call to `position::position(int)'
main.cpp:7: error: candidates are: position::position(const position&)
main.cpp:14: error: position::position()
Compiler version: g++ (GCC) 3.3.5-20050130 (Gentoo Linux
3.3.5.20050130-r1, ssp-3.3.5.20050130-1, pie-8.7.7.1)

Here's the cut down code. I'd greatly appreciate it if someone could
point me towards what I'm doing wrong. Hopefully I'm just missing
something elementary. ( I'm quite new to these boost features. )

On a side note, has anyone come up with a good method of wrapping
these rather long SFINAE calls?

Thanks,
- Scott McMurray

// begin code //

#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>

class position {
  public:
    typedef position my_type;
    typedef unsigned wrapped_type;
  private:
    wrapped_type m_data;
  public:
    position() {}

    // This works fine
    explicit position(boost::enable_if<
                                    boost::is_convertible<int, wrapped_type>,
                                int>::type f)
     : m_data( f ) {}

/*
    // But if I try this, I get the errors
    template <typename fT>
    explicit position(typename boost::enable_if<
                                    boost::is_convertible<fT, wrapped_type>,
                                fT>::type f)
     : m_data( f ) {}
*/

};

int main(int argc, char* argv[]) {

    position x = position(5);

}

// end code //


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net