diff --git a/doc/html/mp11.html b/doc/html/mp11.html index 53c0e68..72adda5 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -84,7 +84,7 @@
mp_identity<T>
mp_identity_t<T>
mp_inherit<T...>
mp_if_c<B, T, E>
mp_if_c<B, T, E...>
mp_if<C,
T, E>
mp_eval_if_c<B, T, F,
@@ -1210,16 +1210,20 @@
-template<bool C, class T, class E> using mp_if_c = /*...*/;
+template<bool C, class T, class... E> using mp_if_c = /*...*/;
- mp_if_c<B, T, E>
- is an alias for T
when
- B
is true
,
- for E
otherwise.
+ mp_if_c<true, T, E...>
+ is an alias for T
. mp_if_c<false, T, E>
is an alias for E
.
+ Otherwise, the result is a substitution failure.
+using R1 = mp_if_c<true, int, void>; // int
+using R2 = mp_if_c<flase, int, void>; // void
+
+template<class I> using void_if_5 = mp_if_c<I::value == 5, void>; // `void` when `I::value` is 5, substitution failure otherwise
+
@@ -1229,10 +1233,8 @@
template<class C, class T, class E> using mp_if = mp_if_c<static_cast<bool>(C::value), T, E>;
- mp_if<C, T, E>
- is an alias for T
when
- C::value
is true
,
- for E
otherwise.
+ Like mp_if_c
, but the first
+ argument is a type.
@@ -2315,7 +2317,7 @@
-Last revised: May 18, 2017 at 11:17:12 GMT
+Last revised: May 18, 2017 at 11:57:59 GMT
diff --git a/doc/mp11/utility.qbk b/doc/mp11/utility.qbk
index 1786265..23d6ce1 100644
--- a/doc/mp11/utility.qbk
+++ b/doc/mp11/utility.qbk
@@ -23,16 +23,21 @@
template struct mp_inherit: T... {};
[endsect]
-[section `mp_if_c`]
- template using mp_if_c = /*...*/;
+[section `mp_if_c`]
+ template using mp_if_c = /*...*/;
-`mp_if_c` is an alias for `T` when `B` is `true`, for `E` otherwise.
+`mp_if_c` is an alias for `T`. `mp_if_c` is an alias for `E`. Otherwise, the result is a substitution failure.
+
+ using R1 = mp_if_c; // int
+ using R2 = mp_if_c; // void
+
+ template using void_if_5 = mp_if_c; // `void` when `I::value` is 5, substitution failure otherwise
[endsect]
[section `mp_if`]
template using mp_if = mp_if_c(C::value), T, E>;
-`mp_if` is an alias for `T` when `C::value` is `true`, for `E` otherwise.
+Like `mp_if_c`, but the first argument is a type.
[endsect]
[section `mp_eval_if_c`]
diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp
index e220b5f..0fe8853 100644
--- a/include/boost/mp11/utility.hpp
+++ b/include/boost/mp11/utility.hpp
@@ -33,9 +33,11 @@ template struct mp_inherit: T... {};
namespace detail
{
-template struct mp_if_c_impl;
+template struct mp_if_c_impl
+{
+};
-template struct mp_if_c_impl
+template struct mp_if_c_impl
{
using type = T;
};
@@ -47,8 +49,8 @@ template struct mp_if_c_impl
} // namespace detail
-template using mp_if_c = typename detail::mp_if_c_impl::type;
-template using mp_if = typename detail::mp_if_c_impl(C::value), T, E>::type;
+template using mp_if_c = typename detail::mp_if_c_impl::type;
+template using mp_if = typename detail::mp_if_c_impl(C::value), T, E...>::type;
// mp_eval_if, mp_eval_if_c
namespace detail
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index da5c569..579fc86 100644
--- a/test/Jamfile.v2
+++ b/test/Jamfile.v2
@@ -75,6 +75,7 @@ run integral.cpp : : : $(REQ) ;
run mp_identity.cpp : : : $(REQ) ;
run mp_inherit.cpp : : : $(REQ) ;
run mp_if.cpp : : : $(REQ) ;
+run mp_if_sf.cpp : : : $(REQ) ;
run mp_eval_if.cpp : : : $(REQ) ;
run mp_valid.cpp : : : $(REQ) ;
run mp_defer.cpp : : : $(REQ) ;
diff --git a/test/mp_if_sf.cpp b/test/mp_if_sf.cpp
new file mode 100644
index 0000000..15ef309
--- /dev/null
+++ b/test/mp_if_sf.cpp
@@ -0,0 +1,24 @@
+
+// Copyright 2017 Peter Dimov.
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
+
+#include
+#include
+#include
+
+int main()
+{
+ using boost::mp11::mp_if;
+ using boost::mp11::mp_valid;
+
+ BOOST_TEST_TRAIT_FALSE((mp_valid));
+ BOOST_TEST_TRAIT_TRUE((mp_valid));
+ BOOST_TEST_TRAIT_FALSE((mp_valid));
+
+ return boost::report_errors();
+}