forked from boostorg/mp11
Merge branch 'develop'
This commit is contained in:
@@ -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,45 @@ 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>;
|
||||
|
||||
// mp_quote
|
||||
template<template<class...> class F> struct mp_quote
|
||||
{
|
||||
template<class... T> using apply = F<T...>;
|
||||
};
|
||||
|
||||
// mp_unquote
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Q, class... T> struct mp_unquote_impl
|
||||
{
|
||||
using type = typename Q::template apply<T...>;
|
||||
};
|
||||
|
||||
template<template<class...> class F, class... T> struct mp_unquote_impl<mp_quote<F>, T...>
|
||||
{
|
||||
using type = F<T...>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Q, class... T> using mp_unquote = typename detail::mp_unquote_impl<Q, T...>::type;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -66,7 +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_defer_if_valid.cpp : : : $(REQ) ;
|
||||
run mp_quote.cpp : : : $(REQ) ;
|
||||
|
||||
# integer_sequence
|
||||
run integer_sequence.cpp : : : $(REQ) ;
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
@@ -7,8 +7,8 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
struct X {};
|
||||
@@ -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();
|
||||
}
|
||||
|
28
test/mp_quote.cpp
Normal file
28
test/mp_quote.cpp
Normal file
@@ -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 <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
struct X {};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp_identity_t;
|
||||
using boost::mp_quote;
|
||||
using boost::mp_unquote;
|
||||
|
||||
using Q = mp_quote<mp_identity_t>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, void>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unquote<Q, int[]>, int[]>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user