From e51ed6cf3da0a05d4a2227f472ab778ff85be4e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 26 Jul 2015 17:43:00 +0300 Subject: [PATCH] Remove mp_defer_if_valid; add mp_identity_t. --- include/boost/mp11/utility.hpp | 17 ++++++++++++++--- test/Jamfile.v2 | 1 - test/mp_defer.cpp | 20 ++++++++++++++++++-- test/mp_defer_if_valid.cpp | 29 ----------------------------- test/mp_identity.cpp | 7 +++++++ 5 files changed, 39 insertions(+), 35 deletions(-) delete mode 100644 test/mp_defer_if_valid.cpp diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index cee33df..b6ac117 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,21 @@ 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>; } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 677dc14..1499b23 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -66,7 +66,6 @@ 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) ; # 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..5ccdcb4 100644 --- a/test/mp_identity.cpp +++ b/test/mp_identity.cpp @@ -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(); }