Opened 16 years ago
Last modified 12 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)
follow-up: 2 comment:1 by , 15 years ago
Description: | modified (diff) |
---|---|
Resolution: | None → invalid |
Severity: | → Showstopper |
Status: | assigned → closed |
comment:2 by , 15 years ago
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 by , 15 years ago
Owner: | changed from | to
---|---|
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 by , 15 years ago
Status: | new → assigned |
---|
It's a nice extension, I like it. Let's get it in.
follow-up: 6 comment:5 by , 15 years ago
Note: it also replaces lazy_enable_if (if_), and enable_if (if_c).
follow-up: 7 comment:6 by , 15 years ago
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 by , 15 years ago
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 by , 15 years ago
Component: | None → mpl |
---|
comment:9 by , 13 years ago
Severity: | Showstopper → Problem |
---|
comment:10 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:11 by , 12 years ago
Cc: | 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.