forked from boostorg/mp11
164 lines
3.2 KiB
C++
164 lines
3.2 KiB
C++
#ifndef BOOST_MP11_FUNCTION_HPP_INCLUDED
|
|
#define BOOST_MP11_FUNCTION_HPP_INCLUDED
|
|
|
|
// Copyright 2015-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 <boost/mp11/integral.hpp>
|
|
#include <boost/mp11/utility.hpp>
|
|
#include <boost/mp11/detail/mp_list.hpp>
|
|
#include <boost/mp11/detail/mp_count.hpp>
|
|
#include <type_traits>
|
|
|
|
namespace boost
|
|
{
|
|
namespace mp11
|
|
{
|
|
|
|
// mp_and<T...>, mp_all<T...>
|
|
|
|
#if BOOST_WORKAROUND( BOOST_MSVC, < 1900 )
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<class... T> struct mp_and_impl;
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_and = mp_to_bool< typename detail::mp_and_impl<T...>::type >;
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<> struct mp_and_impl<>
|
|
{
|
|
using type = mp_true;
|
|
};
|
|
|
|
template<class T> struct mp_and_impl<T>
|
|
{
|
|
using type = T;
|
|
};
|
|
|
|
template<class T1, class... T> struct mp_and_impl<T1, T...>
|
|
{
|
|
using type = mp_eval_if< mp_not<T1>, T1, mp_and, T... >;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_all = mp_bool< mp_count_if< mp_list<T...>, mp_to_bool >::value == sizeof...(T) >;
|
|
|
|
#else
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<class L, class E = void> struct mp_and_impl
|
|
{
|
|
using type = mp_false;
|
|
};
|
|
|
|
void mp_and_impl_f(...);
|
|
|
|
template<class... T> struct mp_and_impl< mp_list<T...>, decltype( mp_and_impl_f( mp_if<T, int>()... ) ) >
|
|
{
|
|
using type = mp_true;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_and = typename detail::mp_and_impl<mp_list<T...>>::type;
|
|
template<class... T> using mp_all = typename detail::mp_and_impl<mp_list<T...>>::type;
|
|
|
|
#endif
|
|
|
|
// mp_or<T...>, mp_any<T...>
|
|
|
|
#if BOOST_WORKAROUND( BOOST_MSVC, < 1900 )
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<class... T> struct mp_or_impl;
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_or = mp_to_bool< typename detail::mp_or_impl<T...>::type >;
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<> struct mp_or_impl<>
|
|
{
|
|
using type = mp_false;
|
|
};
|
|
|
|
template<class T> struct mp_or_impl<T>
|
|
{
|
|
using type = T;
|
|
};
|
|
|
|
template<class T1, class... T> struct mp_or_impl<T1, T...>
|
|
{
|
|
using type = mp_eval_if< T1, T1, mp_or, T... >;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_any = mp_bool< mp_count_if< mp_list<T...>, mp_to_bool >::value != 0 >;
|
|
|
|
#else
|
|
|
|
namespace detail
|
|
{
|
|
|
|
template<class L, class E = void> struct mp_or_impl
|
|
{
|
|
using type = mp_true;
|
|
};
|
|
|
|
void mp_and_impl_f(...);
|
|
|
|
template<class... T> struct mp_or_impl< mp_list<T...>, decltype( mp_and_impl_f( mp_if<mp_not<T>, int>()... ) ) >
|
|
{
|
|
using type = mp_false;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_or = typename detail::mp_or_impl<mp_list<T...>>::type;
|
|
template<class... T> using mp_any = typename detail::mp_or_impl<mp_list<T...>>::type;
|
|
|
|
#endif
|
|
|
|
// mp_same<T...>
|
|
namespace detail
|
|
{
|
|
|
|
template<class... T> struct mp_same_impl;
|
|
|
|
template<> struct mp_same_impl<>
|
|
{
|
|
using type = mp_true;
|
|
};
|
|
|
|
template<class T1, class... T> struct mp_same_impl<T1, T...>
|
|
{
|
|
using type = mp_all<std::is_same<T1, T>...>;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<class... T> using mp_same = typename detail::mp_same_impl<T...>::type;
|
|
|
|
} // namespace mp11
|
|
} // namespace boost
|
|
|
|
#endif // #ifndef BOOST_MP11_FUNCTION_HPP_INCLUDED
|