From e51ed6cf3da0a05d4a2227f472ab778ff85be4e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 26 Jul 2015 17:43:00 +0300 Subject: [PATCH 1/3] 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(); } From d314c868bf553d0742c40dca7b725b7fc3c97a03 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 26 Jul 2015 17:47:31 +0300 Subject: [PATCH 2/3] Fix include order. --- test/mp_identity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mp_identity.cpp b/test/mp_identity.cpp index 5ccdcb4..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 {}; From 6af4bbc11327724334907926dc09f6a0d8ce9596 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 26 Jul 2015 17:55:05 +0300 Subject: [PATCH 3/3] Add mp_quote, mp_unquote. --- include/boost/mp11/utility.hpp | 24 ++++++++++++++++++++++++ test/Jamfile.v2 | 1 + test/mp_quote.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 test/mp_quote.cpp diff --git a/include/boost/mp11/utility.hpp b/include/boost/mp11/utility.hpp index b6ac117..a438a33 100644 --- a/include/boost/mp11/utility.hpp +++ b/include/boost/mp11/utility.hpp @@ -101,6 +101,30 @@ struct mp_no_type 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 #endif // #ifndef BOOST_MP11_UTILITY_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1499b23..76efec9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -66,6 +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_quote.cpp : : : $(REQ) ; # integer_sequence run integer_sequence.cpp : : : $(REQ) ; 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(); +}