From 570acee866c6b39df2026f1e3387f5754fb0c7e5 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 14 May 2023 19:45:09 +0300 Subject: [PATCH] Add mp_value; enable mp_rename on value lists. Refs #53. --- include/boost/mp11/detail/config.hpp | 11 +++++++ include/boost/mp11/detail/mp_rename.hpp | 20 ++++++++--- include/boost/mp11/detail/mp_value.hpp | 25 ++++++++++++++ include/boost/mp11/integral.hpp | 1 + test/Jamfile | 2 ++ test/mp_rename_2.cpp | 44 +++++++++++++++++++++++++ test/mp_value.cpp | 40 ++++++++++++++++++++++ 7 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 include/boost/mp11/detail/mp_value.hpp create mode 100644 test/mp_rename_2.cpp create mode 100644 test/mp_value.cpp diff --git a/include/boost/mp11/detail/config.hpp b/include/boost/mp11/detail/config.hpp index 764bd59..44686c7 100644 --- a/include/boost/mp11/detail/config.hpp +++ b/include/boost/mp11/detail/config.hpp @@ -123,6 +123,17 @@ # endif #endif +// BOOST_MP11_HAS_TEMPLATE_AUTO + +#if defined(__cpp_nontype_template_parameter_auto) && __cpp_nontype_template_parameter_auto >= 201606L +# define BOOST_MP11_HAS_TEMPLATE_AUTO +#endif + +#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 ) +// mp_value<0> is bool, mp_value<-1L> is int, etc +# undef BOOST_MP11_HAS_TEMPLATE_AUTO +#endif + // BOOST_MP11_DEPRECATED(msg) #if BOOST_MP11_WORKAROUND( BOOST_MP11_CLANG, < 304 ) diff --git a/include/boost/mp11/detail/mp_rename.hpp b/include/boost/mp11/detail/mp_rename.hpp index 5af6fc4..dde8f6f 100644 --- a/include/boost/mp11/detail/mp_rename.hpp +++ b/include/boost/mp11/detail/mp_rename.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_MP11_DETAIL_MP_RENAME_HPP_INCLUDED #define BOOST_MP11_DETAIL_MP_RENAME_HPP_INCLUDED -// Copyright 2015-2021 Peter Dimov. +// Copyright 2015-2023 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -9,6 +9,8 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include +#include namespace boost { @@ -19,21 +21,31 @@ namespace mp11 namespace detail { -template class B> struct mp_rename_impl +template class B> struct mp_rename_impl { // An error "no type named 'type'" here means that the first argument to mp_rename is not a list }; -template class A, class... T, template class B> struct mp_rename_impl, B>: mp_defer +template class L, class... T, template class B> struct mp_rename_impl, B>: mp_defer { }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto... A, template class B> struct mp_rename_impl, B>: mp_defer...> +{ +}; + +#endif + } // namespace detail -template class B> using mp_rename = typename detail::mp_rename_impl::type; +template class B> using mp_rename = typename detail::mp_rename_impl::type; +// mp_apply template class F, class L> using mp_apply = typename detail::mp_rename_impl::type; +// mp_apply_q template using mp_apply_q = typename detail::mp_rename_impl::type; } // namespace mp11 diff --git a/include/boost/mp11/detail/mp_value.hpp b/include/boost/mp11/detail/mp_value.hpp new file mode 100644 index 0000000..d0e5982 --- /dev/null +++ b/include/boost/mp11/detail/mp_value.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED +#define BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED + +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +namespace boost +{ +namespace mp11 +{ + +template using mp_value = std::integral_constant; + +} // namespace mp11 +} // namespace boost + +#endif // #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#endif // #ifndef BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED diff --git a/include/boost/mp11/integral.hpp b/include/boost/mp11/integral.hpp index 0671673..1b4fea3 100644 --- a/include/boost/mp11/integral.hpp +++ b/include/boost/mp11/integral.hpp @@ -9,6 +9,7 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include #include #include diff --git a/test/Jamfile b/test/Jamfile index 4a308a8..05ea4f5 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -34,6 +34,7 @@ run mp_third.cpp ; run mp_push_front.cpp ; run mp_push_back.cpp ; run mp_rename.cpp ; +run mp_rename_2.cpp ; run mp_append.cpp ; run mp_append_2.cpp ; run mp_append_sf.cpp ; @@ -133,6 +134,7 @@ run mp_join.cpp ; # integral run integral.cpp ; +run mp_value.cpp ; # utility run mp_identity.cpp ; diff --git a/test/mp_rename_2.cpp b/test/mp_rename_2.cpp new file mode 100644 index 0000000..70c187f --- /dev/null +++ b/test/mp_rename_2.cpp @@ -0,0 +1,44 @@ +// Copyright 2015-2023 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include + +template struct L {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_rename; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_int; + using boost::mp11::mp_size_t; + + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list<>); + + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list); + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list); + + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list>); + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list>); + + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list>); + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list>); + + BOOST_TEST_TRAIT_SAME(mp_rename, mp_list>, mp_list, mp_size_t<0>>); + + return boost::report_errors(); +} + +#endif diff --git a/test/mp_value.cpp b/test/mp_value.cpp new file mode 100644 index 0000000..a81854d --- /dev/null +++ b/test/mp_value.cpp @@ -0,0 +1,40 @@ +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include +#include + +int main() +{ + using boost::mp11::mp_value; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::integral_constant>)); + + return boost::report_errors(); +} + +#endif