Boost logo

Proto :

Subject: Re: [proto] Using a derived class as terminals in Boost.proto
From: Frank Winter (fwinter_at_[hidden])
Date: 2016-04-14 13:04:06


I made some progress. If I specialize struct VectorSubscriptCtx::eval
with Vector10, like

struct VectorSubscriptCtx
{
VectorSubscriptCtx(std::size_t i) : i_(i) {}

template<typename Expr, typename EnableIf = void>
struct eval
: proto::default_eval<Expr, VectorSubscriptCtx const>
{};

template<typename Expr>
struct eval<
Expr
, typename boost::enable_if<
proto::matches<Expr, proto::terminal< Vector10 > >
>::type
>
{
//..
}
};

then it works (is was specialized with Vector). It also works when using
the Boost _ literal (match anything), like

template<typename Expr>
struct eval<
Expr
, typename boost::enable_if<
proto::matches<Expr, proto::terminal< _ > >
>::type

However, I feel this is not good style. Can this be expressed with the
is_base_of trait instead?

On 04/14/2016 10:10 AM, Mathias Gaunard wrote:
> On 14 April 2016 at 14:43, Frank Winter <fwinter_at_[hidden]
> <mailto:fwinter_at_[hidden]>> wrote:
>
> Hi all!
>
> Suppose you'd want to implement a simple EDSL (Embedded Domain
> Specific Language) with Boost.proto with the following requirements:
>
> Custom class 'Vector' as terminal
> Classes derived from 'Vector' are working terminals too, e.g.
> Vector10
>
> [...]
>
> template<typename T>
> struct IsVector
> : mpl::false_
> {};
>
>
> template<>
> struct IsVector< Vector >
> : mpl::true_
> {};
>
>
> Surely this should be true for all types derived from Vector.
>
> template<typename T, typename Enable = void>
> struct IsVector
> : mpl::false_
> {};
>
> template<typename T>
> struct IsVector<T, typanem enable_if< is_base_of<Vector, T> >::type>
> : mpl::true_
> {};
>
>
> _______________________________________________
> proto mailing list
> proto_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/proto
>


Proto list run by eric at boostpro.com