summaryrefslogtreecommitdiff
path: root/boost/hana/detail/index_if.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:24:46 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:25:39 +0900
commit4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch)
treefd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/hana/detail/index_if.hpp
parentb5c87084afaef42b2d058f68091be31988a6a874 (diff)
downloadboost-upstream/1.65.0.tar.gz
boost-upstream/1.65.0.tar.bz2
boost-upstream/1.65.0.zip
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/hana/detail/index_if.hpp')
-rw-r--r--boost/hana/detail/index_if.hpp68
1 files changed, 26 insertions, 42 deletions
diff --git a/boost/hana/detail/index_if.hpp b/boost/hana/detail/index_if.hpp
index 8224f74be8..f643eb76ff 100644
--- a/boost/hana/detail/index_if.hpp
+++ b/boost/hana/detail/index_if.hpp
@@ -3,6 +3,7 @@
Defines `boost::hana::detail::index_if`.
@copyright Louis Dionne 2013-2017
+@copyright Jason Rice 2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
@@ -11,61 +12,44 @@ Distributed under the Boost Software License, Version 1.0.
#define BOOST_HANA_DETAIL_INDEX_IF_HPP
#include <boost/hana/config.hpp>
-#include <boost/hana/core/when.hpp>
+#include <boost/hana/detail/decay.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/optional.hpp>
#include <cstddef>
#include <utility>
BOOST_HANA_NAMESPACE_BEGIN namespace detail {
- template <typename ...T>
- struct pack {
- static constexpr std::size_t length = sizeof...(T);
+ template <std::size_t i, std::size_t N, bool Done>
+ struct index_if_helper;
+
+ template <std::size_t i, std::size_t N>
+ struct index_if_helper<i, N, false> {
+ template <typename Pred, typename X1, typename ...Xs>
+ using f = typename index_if_helper<i + 1, N,
+ static_cast<bool>(detail::decay<decltype(
+ std::declval<Pred>()(std::declval<X1>()))>::type::value)
+ >::template f<Pred, Xs...>;
};
- template <typename T>
- struct make_pack;
-
- template <template <typename...> class Template, typename ...T>
- struct make_pack<Template<T...>> {
- using type = pack<T...>;
- };
-
- template <typename T> struct make_pack<T const> : make_pack<T> { };
- template <typename T> struct make_pack<T&> : make_pack<T> { };
- template <typename T> struct make_pack<T&&> : make_pack<T> { };
-
-
- //! @ingroup group-details
- //! Returns the index of the first element of the `pack<>` that satisfies
- //! the predicate, or the size of the pack if there is no such element.
- //!
- //! @note
- //! The predicate must return an `IntegralConstant` that can be explicitly
- //! converted to `bool`.
- template <typename Pred, typename Ts, typename = when<true>>
- struct index_if;
-
- //! @cond
- template <typename Pred, typename T, typename ...Ts>
- struct index_if<Pred, pack<T, Ts...>, when<static_cast<bool>(decltype(
- std::declval<Pred>()(std::declval<T>())
- )::value)>> {
- static constexpr std::size_t value = 0;
+ template <std::size_t N>
+ struct index_if_helper<N, N, false> {
+ template <typename ...>
+ using f = hana::optional<>;
};
- template <typename Pred, typename T, typename ...Ts>
- struct index_if<Pred, pack<T, Ts...>, when<!static_cast<bool>(decltype(
- std::declval<Pred>()(std::declval<T>())
- )::value)>> {
- static constexpr std::size_t value = 1 + index_if<Pred, pack<Ts...>>::value;
+ template <std::size_t i, std::size_t N>
+ struct index_if_helper<i, N, true> {
+ template <typename ...>
+ using f = hana::optional<hana::size_t<i - 1>>;
};
- template <typename Pred>
- struct index_if<Pred, pack<>> {
- static constexpr std::size_t value = 0;
+ template <typename Pred, typename ...Xs>
+ struct index_if {
+ using type = typename index_if_helper<0, sizeof...(Xs), false>
+ ::template f<Pred, Xs...>;
};
- //! @endcond
} BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_DETAIL_INDEX_IF_HPP