Remove mp_defer_if_valid; add mp_identity_t.

This commit is contained in:
Peter Dimov
2015-07-26 17:43:00 +03:00
parent bd9e5f9c41
commit e51ed6cf3d
5 changed files with 39 additions and 35 deletions

View File

@@ -19,6 +19,9 @@ template<class T> struct mp_identity
using type = T;
};
// mp_identity_t
template<class T> using mp_identity_t = T;
// mp_inherit
template<class... T> struct mp_inherit: T... {};
@@ -82,13 +85,21 @@ template<template<class...> class F, class... T> struct mp_valid_impl
template<template<class...> class F, class... T> using mp_valid = typename detail::mp_valid_impl<F, T...>::type;
// mp_defer
template<template<class...> class F, class... T> struct mp_defer
namespace detail
{
template<template<class...> class F, class... T> struct mp_defer_impl
{
using type = F<T...>;
};
// mp_defer_if_valid
template<template<class...> class F, class... T> using mp_defer_if_valid = mp_if<mp_valid<F, T...>, mp_defer<F, T...>, mp_inherit<>>;
struct mp_no_type
{
};
} // namespace detail
template<template<class...> class F, class... T> using mp_defer = mp_if<mp_valid<F, T...>, detail::mp_defer_impl<F, T...>, detail::mp_no_type>;
} // namespace boost

View File

@@ -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) ;

View File

@@ -8,19 +8,35 @@
#include <boost/mp11/utility.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
template<class T> using add_pointer = T*;
template<class T> struct has_type
{
template<class U> static boost::mp_true f( boost::mp_identity<typename U::type>* );
template<class U> static boost::mp_false f( ... );
using type = decltype( f<T>(0) );
static const auto value = type::value;
};
using boost::mp_defer;
template<class T> using add_pointer_impl = mp_defer<add_pointer, T>;
template<class T> using add_pointer = T*;
template<class... T> using add_pointer_impl = mp_defer<add_pointer, T...>;
int main()
{
BOOST_TEST_TRAIT_TRUE((has_type<add_pointer_impl<void>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<add_pointer_impl<void>::type, void*>));
BOOST_TEST_TRAIT_TRUE((has_type<add_pointer_impl<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<add_pointer_impl<int>::type, int*>));
BOOST_TEST_TRAIT_FALSE((has_type<add_pointer_impl<>>));
BOOST_TEST_TRAIT_FALSE((has_type<add_pointer_impl<void, void>>));
return boost::report_errors();
}

View File

@@ -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 <boost/mp11/utility.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
using boost::mp_defer_if_valid;
using boost::mp_identity;
template<class... T> using mp_identity_2 = typename mp_defer_if_valid<mp_identity, T...>::type;
int main()
{
using boost::mp_valid;
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_identity_2>));
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_identity_2, void>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity_2<void>, mp_identity<void>>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_identity_2, void, void>));
return boost::report_errors();
}

View File

@@ -22,5 +22,12 @@ int main()
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<int const[]>::type, int const[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<X>::type, X>));
using boost::mp_identity_t;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity_t<void const volatile>, void const volatile>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity_t<void()>, void()>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity_t<int const[]>, int const[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity_t<X>, X>));
return boost::report_errors();
}