Sprout/sprout/tpp/algorithm/one_of.hpp

105 lines
3.3 KiB
C++
Raw Permalink Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
Copyright (c) 2011-2019 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
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)
=============================================================================*/
2012-11-02 13:00:10 +00:00
#ifndef SPROUT_TPP_ALGORITHM_ONE_OF_HPP
#define SPROUT_TPP_ALGORITHM_ONE_OF_HPP
2014-09-20 03:55:29 +00:00
#include <type_traits>
2012-11-02 13:00:10 +00:00
#include <sprout/config.hpp>
2014-09-20 03:55:29 +00:00
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/type_traits/integral_constant.hpp>
2014-09-20 03:55:29 +00:00
#include <sprout/type/type_tuple.hpp>
2012-11-02 13:00:10 +00:00
namespace sprout {
namespace tpp {
namespace detail {
2014-09-20 03:55:29 +00:00
template<typename Tup, std::size_t First, std::size_t Last, bool = (Last - First == 1)>
struct one_of_impl_1
2014-12-10 10:54:12 +00:00
: public sprout::bool_constant<!std::tuple_element<First, Tup>::type::value>
2012-11-02 13:00:10 +00:00
{};
2014-09-20 03:55:29 +00:00
template<typename Tup, std::size_t First, std::size_t Last>
struct one_of_impl_1<Tup, First, Last, false>
2014-12-10 10:54:12 +00:00
: public sprout::bool_constant<
2014-09-20 03:55:29 +00:00
sprout::tpp::detail::one_of_impl_1<Tup, First, (First + Last) / 2>::value
&& sprout::tpp::detail::one_of_impl_1<Tup, (First + Last) / 2, Last>::value
>
2012-11-02 13:00:10 +00:00
{};
2014-09-20 03:55:29 +00:00
template<typename Tup, std::size_t First, std::size_t Last, bool = (Last - First == 1)>
struct one_of_impl
: public std::tuple_element<First, Tup>::type
2012-11-02 13:00:10 +00:00
{};
2014-09-20 03:55:29 +00:00
template<typename Tup, std::size_t First, std::size_t Last>
struct one_of_impl<Tup, First, Last, false>
2014-12-10 10:54:12 +00:00
: public sprout::bool_constant<
2014-09-20 03:55:29 +00:00
sprout::tpp::detail::one_of_impl<Tup, First, (First + Last) / 2>::value
? sprout::tpp::detail::one_of_impl_1<Tup, (First + Last) / 2, Last>::value
: sprout::tpp::detail::one_of_impl<Tup, (First + Last) / 2, Last>::value
>
2012-11-02 13:00:10 +00:00
{};
} // namespace detail
//
// one_of
//
template<typename... Types>
struct one_of
2014-09-20 03:55:29 +00:00
: public sprout::tpp::detail::one_of_impl<sprout::types::type_tuple<Types...>, 0, sizeof...(Types)>
{};
template<>
struct one_of<>
: public sprout::false_type
{};
//
// one_of_c
//
template<bool... Values>
struct one_of_c
2014-12-10 10:54:12 +00:00
: public sprout::tpp::one_of<sprout::bool_constant<Values>...>
2012-11-02 13:00:10 +00:00
{};
2014-09-20 03:55:29 +00:00
// namespace detail {
// template<bool... Values>
// struct one_of_impl;
// template<>
// struct one_of_impl<>
// : public sprout::false_type
// {};
// template<>
// struct one_of_impl<true>
// : public sprout::true_type
// {};
// template<>
// struct one_of_impl<false>
// : public sprout::false_type
// {};
// template<bool... Tail>
// struct one_of_impl<true, Tail...>
// : public sprout::tpp::none_of_c<Tail...>
// {};
// template<bool... Tail>
// struct one_of_impl<false, Tail...>
2014-12-10 10:54:12 +00:00
// : public sprout::bool_constant<sprout::tpp::detail::one_of_impl<Tail...>::value>
2014-09-20 03:55:29 +00:00
// {};
// } // namespace detail
// //
// // one_of_c
// //
// template<bool... Values>
// struct one_of_c
// : public sprout::tpp::detail::one_of_impl<Values...>
// {};
// //
// // one_of
// //
// template<typename... Types>
// struct one_of
// : public sprout::tpp::one_of_c<Types::value...>
// {};
2012-11-02 13:00:10 +00:00
} // namespace tpp
} // namespace sprout
#endif // #ifndef SPROUT_TPP_ALGORITHM_ONE_OF_HPP