diff --git a/libs/tuple/test/tuple.cpp b/libs/tuple/test/tuple.cpp index b1ee78e9..ab868c20 100644 --- a/libs/tuple/test/tuple.cpp +++ b/libs/tuple/test/tuple.cpp @@ -193,6 +193,14 @@ namespace testspr { TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } + // get + TESTSPR_BOTH_ASSERT(sprout::tuples::get(tup1) == 1); + TESTSPR_BOTH_ASSERT(sprout::tuples::get(tup1) == 1.0); + { + auto tup3 = tup1; + TESTSPR_ASSERT(sprout::tuples::get(tup3) == 1); + TESTSPR_ASSERT(sprout::tuples::get(tup3) == 1.0); + } // tuple_size TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 2); diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index 409bac39..66c86821 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include #include namespace sprout { @@ -107,6 +110,18 @@ namespace sprout { return sprout_tuple_detail::call_tuple_get(SPROUT_FORWARD(T, t)); } + // + // get + // + template + inline SPROUT_CONSTEXPR decltype(sprout::tuples::get<(sprout::types::find_index::type, Type>::value)>(std::declval())) + get(T&& t) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<(sprout::types::find_index::type, Type>::value)>(std::declval())) + { + static_assert(sprout::types::count::type, Type>::value == 1, "Requires: The type 'Type' occurs exactly once in type list."); + return sprout::tuples::get<(sprout::types::find_index::type, Type>::value)>(SPROUT_FORWARD(T, t)); + } + // // nested_get // diff --git a/sprout/type/algorithm.hpp b/sprout/type/algorithm.hpp index af26668b..03c5f212 100644 --- a/sprout/type/algorithm.hpp +++ b/sprout/type/algorithm.hpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/sprout/type/algorithm/contains.hpp b/sprout/type/algorithm/contains.hpp index a1776f87..bc22c28b 100644 --- a/sprout/type/algorithm/contains.hpp +++ b/sprout/type/algorithm/contains.hpp @@ -19,7 +19,7 @@ namespace sprout { // template struct contains - : public sprout::types::find_index::found + : public sprout::types::find_index::is_found {}; #if SPROUT_USE_TEMPLATE_ALIASES diff --git a/sprout/type/algorithm/contains_if.hpp b/sprout/type/algorithm/contains_if.hpp index 7cdce449..eec1e940 100644 --- a/sprout/type/algorithm/contains_if.hpp +++ b/sprout/type/algorithm/contains_if.hpp @@ -19,7 +19,7 @@ namespace sprout { // template struct contains_if - : public sprout::types::find_index_if::found + : public sprout::types::find_index_if::is_found {}; #if SPROUT_USE_TEMPLATE_ALIASES diff --git a/sprout/type/algorithm/count.hpp b/sprout/type/algorithm/count.hpp new file mode 100644 index 00000000..6077f0ee --- /dev/null +++ b/sprout/type/algorithm/count.hpp @@ -0,0 +1,81 @@ +/*============================================================================= + Copyright (c) 2011-2015 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_COUNT_HPP +#define SPROUT_TYPE_ALGORITHM_COUNT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template< + typename Tuple, typename T, std::size_t First, + std::size_t Size, + bool C0 = (Size == 1) + > + struct count_impl; + template< + typename Tuple, typename T, std::size_t First, + std::size_t Size + > + struct count_impl + : public sprout::integral_constant< + std::size_t, (std::is_same::type, T>::value ? 1 : 0) + > + {}; + template< + typename Tuple, typename T, std::size_t First, + std::size_t Size + > + struct count_impl + : public sprout::integral_constant< + std::size_t, + sprout::types::detail::count_impl< + Tuple, T, First, + Size / 2 + >::value + + sprout::types::detail::count_impl< + Tuple, T, First + Size / 2, + Size - Size / 2 + >::value + > + {}; + template::value> + struct count + : public sprout::types::detail::count_impl + {}; + template + struct count + : public sprout::integral_constant + {}; + } // namespace detail + // + // count + // + template + struct count + : public sprout::types::detail::count + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using count_t = typename sprout::types::count::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t count_v = sprout::types::count::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_COUNT_HPP diff --git a/sprout/type/algorithm/count_if.hpp b/sprout/type/algorithm/count_if.hpp new file mode 100644 index 00000000..c051dfd2 --- /dev/null +++ b/sprout/type/algorithm/count_if.hpp @@ -0,0 +1,81 @@ +/*============================================================================= + Copyright (c) 2011-2015 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_ALGORITHM_COUNT_IF_HPP +#define SPROUT_TYPE_ALGORITHM_COUNT_IF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template< + typename Tuple, typename Predicate, std::size_t First, + std::size_t Size, + bool C0 = (Size == 1) + > + struct count_if_impl; + template< + typename Tuple, typename Predicate, std::size_t First, + std::size_t Size + > + struct count_if_impl + : public sprout::integral_constant< + std::size_t, (sprout::types::apply::type>::type::value ? 1 : 0) + > + {}; + template< + typename Tuple, typename Predicate, std::size_t First, + std::size_t Size + > + struct count_if_impl + : public sprout::integral_constant< + std::size_t, + sprout::types::detail::count_if_impl< + Tuple, Predicate, First, + Size / 2 + >::value + + sprout::types::detail::count_if_impl< + Tuple, Predicate, First + Size / 2, + Size - Size / 2 + >::value + > + {}; + template::value> + struct count_if + : public sprout::types::detail::count_if_impl + {}; + template + struct count_if + : public sprout::integral_constant + {}; + } // namespace detail + // + // count_if + // + template + struct count_if + : public sprout::types::detail::count_if + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using count_if_t = typename sprout::types::count_if::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR std::size_t count_if_v = sprout::types::count_if::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_COUNT_IF_HPP diff --git a/sprout/type/algorithm/detail/find_index_result.hpp b/sprout/type/algorithm/detail/find_index_result.hpp index 68ad19db..72332740 100644 --- a/sprout/type/algorithm/detail/find_index_result.hpp +++ b/sprout/type/algorithm/detail/find_index_result.hpp @@ -21,7 +21,7 @@ namespace sprout { : public sprout::integral_constant { public: - typedef sprout::bool_constant::value> found; + typedef sprout::bool_constant::value> is_found; }; } // namespace detail } // namespace types diff --git a/sprout/type/algorithm/find_index_if.hpp b/sprout/type/algorithm/find_index_if.hpp index 4a108db3..c5aa3a48 100644 --- a/sprout/type/algorithm/find_index_if.hpp +++ b/sprout/type/algorithm/find_index_if.hpp @@ -8,7 +8,6 @@ #ifndef SPROUT_TYPE_ALGORITHM_FIND_INDEX_IF_HPP #define SPROUT_TYPE_ALGORITHM_FIND_INDEX_IF_HPP -#include #include #include #include