Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-10-03 02:22:02


David B. Held wrote:
> With concrete types, if_<> works just fine on bcc. However, with
> dependent names, it strips cv qualifiers (apparently. This can be
> demonstrated by replacing this_type with T (same action) or int
> (correct behaviour...assuming you modify the example appropriately,
> of course). Any advice on how to get this important construct
> working would be appreciated.

Well, given that, apparently, Borland fails on the following code as well, I
don't think there is much we can do about the bug in general:

    #include "boost/type_traits/add_const.hpp"
    #include "boost/type_traits/is_const.hpp"
    #include "boost/static_assert.hpp"

    template< typename T > struct my
    {
        typedef typename boost::add_const<T>::type type;
        BOOST_STATIC_ASSERT(boost::is_const<type>::value);
    };

    int main()
    {
        sizeof(my<int>::type);
        sizeof(my<int const>::type); //!!
    }

But here's a workaround for your particular example:

    #include <boost/mpl/if.hpp>

    template <typename T>
    class ptr
    {
        typedef ptr this_type;
        typedef typename boost::mpl::if_c<
              false
            , this_type&
            , this_type const&
>::type copy_arg_ref;

    public:
        ptr() { }
        ptr(copy_arg_ref p)
        {
            p = p;
        }
    };

    int main()
    {
        ptr<int> p;
        ptr<int> q(p);
    }

HTH,
Aleksey


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