Boost logo

Boost :

From: Vincent Finn (vincent_finn_at_[hidden])
Date: 2002-12-18 07:13:50


Hi,

A thought occurred to me about optional<>

This is again about having the constructor non-explicit
(I would really like to have this :-)

could you use partial specialization to do this ?

The code below has the desired behaviour.
usage gives the programmer the ability to choose whether the constructor
is explicit or not

Are there any problems with this approach ?

        Vin

template< typename T, bool bIsExplicit = true >
class C
{
public:
    C( const T )
    {
            g = 9;
    };
};

template< typename T >
class C< T, true >
{
public:
    explicit C( const T )
    {
             g = 2;
    }
};

void test1(C<int> c)
{
        int grr = 90;
}

void test2(C<int, false> c)
{
        int grr = 99;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk