add tpp one_of

This commit is contained in:
bolero-MURAKAMI 2012-11-02 22:00:10 +09:00
parent 2b366b5f03
commit ac80a04970
5 changed files with 94 additions and 9 deletions

View file

@ -5,5 +5,6 @@
#include <sprout/tpp/algorithm/all_of.hpp> #include <sprout/tpp/algorithm/all_of.hpp>
#include <sprout/tpp/algorithm/any_of.hpp> #include <sprout/tpp/algorithm/any_of.hpp>
#include <sprout/tpp/algorithm/none_of.hpp> #include <sprout/tpp/algorithm/none_of.hpp>
#include <sprout/tpp/algorithm/one_of.hpp>
#endif // #ifndef SPROUT_TPP_ALGORITHM_HPP #endif // #ifndef SPROUT_TPP_ALGORITHM_HPP

View file

@ -7,9 +7,13 @@
namespace sprout { namespace sprout {
namespace tpp { namespace tpp {
namespace detail { namespace detail {
template<bool Head, bool... Tail> template<bool... Values>
struct all_of_impl; struct all_of_impl;
template<> template<>
struct all_of_impl<>
: public std::true_type
{};
template<>
struct all_of_impl<true> struct all_of_impl<true>
: public std::true_type : public std::true_type
{}; {};
@ -27,12 +31,19 @@ namespace sprout {
{}; {};
} // namespace detail } // namespace detail
// //
// all_of // all_of_c
// //
template<bool... Values> template<bool... Values>
struct all_of struct all_of_c
: public sprout::tpp::detail::all_of_impl<Values...> : public sprout::tpp::detail::all_of_impl<Values...>
{}; {};
//
// all_of
//
template<typename... Types>
struct all_of
: public sprout::tpp::all_of_c<Types::value...>
{};
} // namespace tpp } // namespace tpp
} // namespace sprout } // namespace sprout

View file

@ -7,9 +7,13 @@
namespace sprout { namespace sprout {
namespace tpp { namespace tpp {
namespace detail { namespace detail {
template<bool Head, bool... Tail> template<bool... Values>
struct any_of_impl; struct any_of_impl;
template<> template<>
struct any_of_impl<>
: public std::false_type
{};
template<>
struct any_of_impl<true> struct any_of_impl<true>
: public std::true_type : public std::true_type
{}; {};
@ -27,12 +31,19 @@ namespace sprout {
{}; {};
} // namespace detail } // namespace detail
// //
// any_of // any_of_c
// //
template<bool... Values> template<bool... Values>
struct any_of struct any_of_c
: public sprout::tpp::detail::any_of_impl<Values...> : public sprout::tpp::detail::any_of_impl<Values...>
{}; {};
//
// any_of
//
template<typename... Types>
struct any_of
: public sprout::tpp::any_of_c<Types::value...>
{};
} // namespace tpp } // namespace tpp
} // namespace sprout } // namespace sprout

View file

@ -7,9 +7,13 @@
namespace sprout { namespace sprout {
namespace tpp { namespace tpp {
namespace detail { namespace detail {
template<bool Head, bool... Tail> template<bool... Values>
struct none_of_impl; struct none_of_impl;
template<> template<>
struct none_of_impl<>
: public std::true_type
{};
template<>
struct none_of_impl<true> struct none_of_impl<true>
: public std::false_type : public std::false_type
{}; {};
@ -27,12 +31,19 @@ namespace sprout {
{}; {};
} // namespace detail } // namespace detail
// //
// none_of // none_of_c
// //
template<bool... Values> template<bool... Values>
struct none_of struct none_of_c
: public sprout::tpp::detail::none_of_impl<Values...> : public sprout::tpp::detail::none_of_impl<Values...>
{}; {};
//
// none_of
//
template<typename... Types>
struct none_of
: public sprout::tpp::none_of_c<Types::value...>
{};
} // namespace tpp } // namespace tpp
} // namespace sprout } // namespace sprout

View file

@ -0,0 +1,51 @@
#ifndef SPROUT_TPP_ALGORITHM_ONE_OF_HPP
#define SPROUT_TPP_ALGORITHM_ONE_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tpp/algorithm/none_of.hpp>
namespace sprout {
namespace tpp {
namespace detail {
template<bool... Values>
struct one_of_impl;
template<>
struct one_of_impl<>
: public std::false_type
{};
template<>
struct one_of_impl<true>
: public std::true_type
{};
template<>
struct one_of_impl<false>
: public std::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...>
: public std::integral_constant<bool, sprout::tpp::detail::one_of_impl<Tail...>::value>
{};
} // 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...>
{};
} // namespace tpp
} // namespace sprout
#endif // #ifndef SPROUT_TPP_ALGORITHM_ONE_OF_HPP