Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL]...if_ and enable_if
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-03-14 23:20:32


on Fri Mar 09 2012, Steven Watanabe <watanabesj-AT-gmail.com> wrote:

> AMDG
>
> On 03/09/2012 07:04 AM, Robert Jones wrote:
>> I'm having a bit of punt into the murky world of metaprogramming, so this
>> might be a bit naive...!
>>
>> I've been using Boost.enable_if for a while, and now I've just encountered
>> Boost.MPL.if_
>> and wonder if enable_if is simply a special case of MPL.if_.
>>
>> Given
>>
>> struct empty { };
>> template <typename T> struct my_condition : /* boost true_ or false_ */;
>>
>> is
>>
>> template <typename T> typename enable_if<my_condition<T>, int>::type f( ) {
>> /* .... */ }
>>
>> the same as
>>
>> template <typename T> typename eval_if<my_condition<T>, identity<int>,
>> empty>::type f( ) { /* ... */ }
>>
>> Or is there some subtlety I'm missing (which is quite likely!)
>>
>
> They aren't the same. You're violating the preconditions of
> mpl::eval_if. This is illegal and only happens to work because
> mpl::eval_if is implemented using metafunction forwarding
> for most compilers.

But there is an implementation of if_ that would actually work as a
substitute for enable_if:

https://svn.boost.org/trac/boost/ticket/799

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net