proposal for metafunction mpl::eval

Hi,
I'm not so much into meta-programming, so I'm not sure whether there's
already an alternative available.
Nevertheless I'd like to propose a new metafunction that simply
evaluates its argument:
template<typename F>
struct eval: F::type
{};
I've found it somehow useful because it avoids syntactical sugar when
specifying a condition to be evaluated for eval_if:
eval_if< eval

On 11 September 2013 21:26, klaus triendl wrote:
Hi,
I'm not so much into meta-programming, so I'm not sure whether there's already an alternative available.
Nevertheless I'd like to propose a new metafunction that simply evaluates its argument:
template<typename F> struct eval: F::type {};
You can only derive from class types, so this can't be used with metafunctions returning scalar types, references, pointers, arrays, or functions. C++11 provides what you want: template<typename F> using eval = typename F::type;

Am Wed, 11 Sep 2013 21:32:00 +0100
schrieb Jonathan Wakely
On 11 September 2013 21:26, klaus triendl wrote:
Hi,
I'm not so much into meta-programming, so I'm not sure whether there's already an alternative available.
Nevertheless I'd like to propose a new metafunction that simply evaluates its argument:
template<typename F> struct eval: F::type {};
You can only derive from class types, so this can't be used with metafunctions returning scalar types, references, pointers, arrays, or functions.
I'm aware of this, however the implementation could be different: template<typename F> struct eval { typedef typename F::type type; } It's similar to eval_if with respect to evaluation.
C++11 provides what you want:
template<typename F> using eval = typename F::type;
That's cool :) It would be interesting of course to have it available in the mpl library... -- klaus triendl

I'm not so much into meta-programming, so I'm not sure whether there's already an alternative available.
Nevertheless I'd like to propose a new metafunction that simply evaluates its argument:
template<typename F> struct eval: F::type {};
You can only derive from class types, so this can't be used with metafunctions returning scalar types, references, pointers, arrays, or functions.
I'm aware of this, however the implementation could be different:
template<typename F> struct eval { typedef typename F::type type; }
This is now a different metafunction - you have to write typename eval<F>::type to get at the type (rather than just eval<F>), which is no better than typename F::type Regards, Nate

Am Wed, 11 Sep 2013 23:01:04 +0000
schrieb Nathan Ridge
You can only derive from class types, so this can't be used with metafunctions returning scalar types, references, pointers, arrays, or functions.
I'm aware of this, however the implementation could be different:
template<typename F> struct eval { typedef typename F::type type; }
This is now a different metafunction - you have to write
typename eval<F>::type
You're damn right! However I don't see a practical problem here: Regarding my motivating case, eval_if anyway expects an integral constant as its evaluation condition, therefore F must yield an integral constant. Regards, klaus

On Sep 12, 2013 8:15 AM, "klaus triendl"
Am Wed, 11 Sep 2013 23:01:04 +0000 schrieb Nathan Ridge
: You can only derive from class types, so this can't be used with metafunctions returning scalar types, references, pointers, arrays, or functions.
I'm aware of this, however the implementation could be different:
template<typename F> struct eval { typedef typename F::type type; }
This is now a different metafunction - you have to write
typename eval<F>::type
You're damn right!
However I don't see a practical problem here: Regarding my motivating case, eval_if anyway expects an integral constant as its evaluation condition, therefore F must yield an integral constant.
What problem are you trying to solve by adding this metafunction?

Hi, On 09/11/13 22:26, klaus triendl wrote:
Nevertheless I'd like to propose a new metafunction that simply evaluates its argument:
template<typename F> struct eval: F::type {};
I've found it somehow useful because it avoids syntactical sugar when specifying a condition to be evaluated for eval_if:
eval_if< eval
>, F1, F2 >; instead of writing:
eval_if< typename apply
::type, F1, F2 >; Any comments on this?
"apply
::type
The "lazy<...>" template takes its argument (a metaprogram) and evaluates every argument of every metafunction call in it. Since eval_if is a special metafunction (its second and third arguments are lazy), it needs the extra lazy_argument templates as well. You can read about it and laziness in metaprograms in the Metamonad user manual (http://abel.web.elte.hu/mpllibs/metamonad/manual.html#lazy-metafunctions) I gave a talk at C++Now this year about Metamonad and the first part of the talk covered laziness in metaprograms. You can watch it here: http://www.youtube.com/watch?v=aIj034VCUD8 Regards, Ábel
participants (4)
-
Abel Sinkovics
-
Jonathan Wakely
-
klaus triendl
-
Nathan Ridge