Opened 12 years ago
Last modified 8 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 )
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
Change History (12)
comment:1 follow-up: 2 Changed 11 years ago by
Description: | modified (diff) |
---|---|
Resolution: | None → invalid |
Severity: | → Showstopper |
Status: | assigned → closed |
comment:2 Changed 11 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 11 years ago by
Owner: | changed from nobody to Aleksey Gurtovoy |
---|---|
Status: | reopened → new |
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 11 years ago by
Status: | new → assigned |
---|
It's a nice extension, I like it. Let's get it in.
comment:5 follow-up: 6 Changed 11 years ago by
Note: it also replaces lazy_enable_if (if_), and enable_if (if_c).
comment:6 follow-up: 7 Changed 11 years ago by
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 Changed 11 years ago by
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 11 years ago by
Component: | None → mpl |
---|
comment:9 Changed 9 years ago by
Severity: | Showstopper → Problem |
---|
comment:10 Changed 8 years ago by
Owner: | changed from Aleksey Gurtovoy to Joel Falcou |
---|---|
Status: | assigned → new |
comment:11 Changed 8 years ago by
Cc: | joel.falcou@… added |
---|---|
Milestone: | → Boost 1.46.0 |
Version: | None → Boost 1.45.0 |
I disagree; it's far too verbose, and thus less clear, when you consider the need for the
template
keyword, which you left out.