Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-18 18:25:11


----- Original Message -----
From: "David B. Held" <dheld_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
To: <boost_at_[hidden]>
Sent: Friday, April 19, 2002 12:11 AM
Subject: [boost] Boostifying Loki::SmartPtr

> I stole Select
> right out of TypeManip, and just inserted where appropriate, because
> I am not sure if Boost already has such a facility, or where it is.
> Obviously, the usage of PTS will require a workaround for portability
> from someone that knows how to do that. I suspect that MPL::select_if
> does what I want, but that's not boost yet. ;)

namespace detail
{
    struct SelectA
    {
        template <typename A, typename B> struct Evaluate
        { typedef A type; }
    }

    struct SelectB
    {
        template <typename A, typename B> struct Evaluate
        { typedef B type; }
    }

    typename <bool Condition> template SelectTrait
    { typedef SelectA type; }
    typename <> template SelectTrait<false>
    { typedef SelectB type; }
}

template Select<bool Condition, typename A, typename B>
{
    typedef typename detail::SelectTrait<Condition>::type Evaluator;
    typedef Evaluator::template Evaluate<A,B>::type type;
};

This works without PTS. You might want to check config/ for macros to be
used instead of "typename" (do all compilers support it?) and "::template"
(same question).
Yes, we need a metaprogramming library.

> I enclosed member templates with
> #ifndef BOOST_NO_MEMBER_TEMPLATES, but offered no
> alternative, since I'm not sure what can be done about those. Is it
> possible to offer a non-nested template alternative?

External friend template functions, probably.

> It also doesn't like:
>
> template <class P, template <class> ThreadingModel>
> class ref_count_mt : public ThreadingModel<ref_count_mt>

Weird.

Giovanni Bajo


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