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 ( ) 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, ssp-, pie-

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?

- Scott McMurray

// begin code //

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

class position {
    typedef position my_type;
    typedef unsigned wrapped_type;
    wrapped_type m_data;
    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, kalb at, bjorn.karlsson at, gregod at, wekempf at