diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index cee33df..a438a33 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -19,6 +19,9 @@ template struct mp_identity using type = T; }; +// mp_identity_t +template using mp_identity_t = T; + // mp_inherit template struct mp_inherit: T... {}; @@ -82,13 +85,45 @@ template class F, class... T> struct mp_valid_impl template class F, class... T> using mp_valid = typename detail::mp_valid_impl::type; // mp_defer -template class F, class... T> struct mp_defer +namespace detail +{ + +template class F, class... T> struct mp_defer_impl { using type = F; }; -// mp_defer_if_valid -template class F, class... T> using mp_defer_if_valid = mp_if, mp_defer, mp_inherit<>>; +struct mp_no_type +{ +}; + +} // namespace detail + +template class F, class... T> using mp_defer = mp_if, detail::mp_defer_impl, detail::mp_no_type>; + +// mp_quote +template class F> struct mp_quote +{ + template using apply = F; +}; + +// mp_unquote +namespace detail +{ + +template struct mp_unquote_impl +{ + using type = typename Q::template apply; +}; + +template class F, class... T> struct mp_unquote_impl, T...> +{ + using type = F; +}; + +} // namespace detail + +template using mp_unquote = typename detail::mp_unquote_impl::type; } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 677dc14..76efec9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -66,7 +66,7 @@ run mp_if.cpp : : : $(REQ) ; run mp_eval_if.cpp : : : $(REQ) ; run mp_valid.cpp : : : $(REQ) ; run mp_defer.cpp : : : $(REQ) ; -run mp_defer_if_valid.cpp : : : $(REQ) ; +run mp_quote.cpp : : : $(REQ) ; # integer_sequence run integer_sequence.cpp : : : $(REQ) ; diff --git a/test/mp_defer.cpp b/test/mp_defer.cpp index 09aa771..e6fdbc7 100644 --- a/test/mp_defer.cpp +++ b/test/mp_defer.cpp @@ -8,19 +8,35 @@ #include +#include #include #include -template using add_pointer = T*; +template struct has_type +{ + template static boost::mp_true f( boost::mp_identity* ); + template static boost::mp_false f( ... ); + + using type = decltype( f(0) ); + + static const auto value = type::value; +}; using boost::mp_defer; -template using add_pointer_impl = mp_defer; +template using add_pointer = T*; +template using add_pointer_impl = mp_defer; int main() { + BOOST_TEST_TRAIT_TRUE((has_type>)); BOOST_TEST_TRAIT_TRUE((std::is_same::type, void*>)); + + BOOST_TEST_TRAIT_TRUE((has_type>)); BOOST_TEST_TRAIT_TRUE((std::is_same::type, int*>)); + BOOST_TEST_TRAIT_FALSE((has_type>)); + BOOST_TEST_TRAIT_FALSE((has_type>)); + return boost::report_errors(); } diff --git a/test/mp_defer_if_valid.cpp b/test/mp_defer_if_valid.cpp deleted file mode 100644 index 32c449b..0000000 --- a/test/mp_defer_if_valid.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -// Copyright 2015 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 - -using boost::mp_defer_if_valid; -using boost::mp_identity; - -template using mp_identity_2 = typename mp_defer_if_valid::type; - -int main() -{ - using boost::mp_valid; - - BOOST_TEST_TRAIT_FALSE((mp_valid)); - BOOST_TEST_TRAIT_TRUE((mp_valid)); - BOOST_TEST_TRAIT_TRUE((std::is_same, mp_identity>)); - BOOST_TEST_TRAIT_FALSE((mp_valid)); - - return boost::report_errors(); -} diff --git a/test/mp_identity.cpp b/test/mp_identity.cpp index 489e971..46ce6a4 100644 --- a/test/mp_identity.cpp +++ b/test/mp_identity.cpp @@ -7,8 +7,8 @@ // http://www.boost.org/LICENSE_1_0.txt -#include #include +#include #include struct X {}; @@ -22,5 +22,12 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_same::type, int const[]>)); BOOST_TEST_TRAIT_TRUE((std::is_same::type, X>)); + using boost::mp_identity_t; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void const volatile>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void()>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int const[]>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, X>)); + return boost::report_errors(); } diff --git a/test/mp_quote.cpp b/test/mp_quote.cpp new file mode 100644 index 0000000..74a8193 --- /dev/null +++ b/test/mp_quote.cpp @@ -0,0 +1,28 @@ + +// Copyright 2015 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 + +struct X {}; + +int main() +{ + using boost::mp_identity_t; + using boost::mp_quote; + using boost::mp_unquote; + + using Q = mp_quote; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int[]>)); + + return boost::report_errors(); +}