From 28c420edf7fa87a539da48203b6e061bd2d4a00e Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 1 Apr 2017 20:01:51 +0300 Subject: [PATCH] Add mp_same. --- include/boost/mp11/function.hpp | 21 +++++++++++++++++++++ test/Jamfile.v2 | 1 + test/mp_same.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/mp_same.cpp diff --git a/include/boost/mp11/function.hpp b/include/boost/mp11/function.hpp index e714aa0..571a24b 100644 --- a/include/boost/mp11/function.hpp +++ b/include/boost/mp11/function.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { @@ -84,6 +85,26 @@ template struct mp_or_impl } // namespace detail +// mp_same +namespace detail +{ + +template struct mp_same_impl; + +template<> struct mp_same_impl<> +{ + using type = mp_true; +}; + +template struct mp_same_impl +{ + using type = mp_all...>; +}; + +} // namespace detail + +template using mp_same = typename detail::mp_same_impl::type; + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index cfc1c36..3bfaec6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -94,6 +94,7 @@ run mp_all.cpp : : : $(REQ) ; run mp_and.cpp : : : $(REQ) ; run mp_any.cpp : : : $(REQ) ; run mp_or.cpp : : : $(REQ) ; +run mp_same.cpp : : : $(REQ) ; # map run mp_map_find.cpp : : : $(REQ) ; diff --git a/test/mp_same.cpp b/test/mp_same.cpp new file mode 100644 index 0000000..5b642ae --- /dev/null +++ b/test/mp_same.cpp @@ -0,0 +1,33 @@ + +// 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_same; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + return boost::report_errors(); +}