Modify

Opened 11 years ago

Last modified 7 years ago

#799 new Feature Requests

mpl::if_

Reported by: nobody Owned by: Joel Falcou
Milestone: Boost 1.46.0 Component: mpl
Version: Boost 1.45.0 Severity: Problem
Keywords: Cc: joel.falcou@…

Description (last modified by Dave Abrahams)

There is an alternative implementation of mpl::if.
This implementation makes code clearer.

We can write:
typename if_
<
  X,
  Y
>
::else_if
<
  Z,
  U
>
::else_
<
  V
>::type

The implementation can be found here:
http://cbear.berlios.de/meta/if.hpp

Attachments (0)

Change History (12)

comment:1 Changed 10 years ago by Dave Abrahams

Description: modified (diff)
Resolution: Noneinvalid
Severity: Showstopper
Status: assignedclosed

I disagree; it's far too verbose, and thus less clear, when you consider the need for the template keyword, which you left out.

  typename if_
  <
    X,
    Y
  >
  ::template else_if
  <
    Z,
    U
  >
  ::template else_
  <
    V
  >::type

comment:2 in reply to:  1 Changed 10 years ago by anonymous

Resolution: invalid
Status: closedreopened

Replying to dave:

I disagree; it's far too verbose, and thus less clear, when you consider the need for the template keyword, which you left out.

Ok, lets compare:

1 condition:

// Boost
typedef Mpl::if_<C, T, E>::type X;

// cbear
typedef Meta::if_<C, T, E>::type X;

5 conditions:

// Boost
template<class C1, class C2, class C3, class C4, class C5>
struct X: 
        Mpl::if_<C1, T1, 
        typename Mpl::if_<C2, T2, 
        typename Mpl::if_<C3, T3, 
        typename Mpl::if_<C4, T4, 
        typename Mpl::if_<C5, T5, 
        E
        >::type 
        >::type 
        >::type 
        >::type 
        >
{
};

// cbear
template<class C1, class C2, class C3, class C4, class C5>
struct X:
        Meta::if_<C1, T1>::
        template else_if<C2, T2>::
        template else_if<C3, T3>::
        template else_if<C4, T4>::
        template else_if<C5, T5>::      
        template else_<E>
{
};

enable if T is integer:

// Boost
template<class T>
T foo(T t, typename boost::enable_if<boost::is_integral<T> >::type* dummy = 0);

// cbear
template<class T>
T foo(T t, typename Meta::if_<boost::is_integral<T> >::type* dummy = 0);

enable if T is integer (returns T) or pointer (returns int):

// Boost
template<class T>
typename Mpl::lazy_enable_if<
        Mpl::or_<boost::is_integral<T>, boost::is_pointer<T> >, // !!!
        Mpl::if_<boost::is_integral<T>, T, int> >::type
foo(T t);

// cbear
template<class T>
typename Meta::if_<boost::is_integral<T>, T>::
template else_if<boost::is_pointer<T>, int>::type
foo(T t);

I would agree with some other arguments. But not with 'it's far too verbose, and thus less clear'. That's false!

comment:3 Changed 10 years ago by Dave Abrahams

Owner: changed from nobody to Aleksey Gurtovoy
Status: reopenednew

Sorry, I hadn't looked at your implementation, so I assumed that you had to use else_ rather than a third argument. I'm beginning to like your suggestion. We'll have to see what Aleksey says.

comment:4 Changed 10 years ago by Aleksey Gurtovoy

Status: newassigned

It's a nice extension, I like it. Let's get it in.

comment:5 Changed 10 years ago by sergey.junk@…

Note: it also replaces lazy_enable_if (if_), and enable_if (if_c).

comment:6 in reply to:  5 ; Changed 10 years ago by Dave Abrahams

Replying to sergey.junk@comrades.id.ua:

Note: it also replaces lazy_enable_if (if_), and enable_if (if_c).

I know, and I like the way it does that, too.

comment:7 in reply to:  6 Changed 10 years ago by anonymous

Replying to dave:

Replying to sergey.junk@comrades.id.ua:

Note: it also replaces lazy_enable_if (if_), and enable_if (if_c).

I know, and I like the way it does that, too.

In case berlios.de dosn't work, see http://cbear.svn.sourceforge.net/viewvc/cbear/trunk/cbear.berlios.de/meta/if.hpp?revision=8&view=markup&pathrev=13

comment:8 Changed 10 years ago by Dave Abrahams

Component: Nonempl

comment:9 Changed 9 years ago by Daniel James

Severity: ShowstopperProblem

comment:10 Changed 7 years ago by anonymous

Owner: changed from Aleksey Gurtovoy to Joel Falcou
Status: assignednew

comment:11 Changed 7 years ago by Joel Falcou

Cc: joel.falcou@… added
Milestone: Boost 1.46.0
Version: NoneBoost 1.45.0

comment:12 Changed 7 years ago by NN

This is a very good alternative. I wish boost had this feature.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Joel Falcou.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.