summaryrefslogtreecommitdiff
path: root/boost/hana/scan_right.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:38:45 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:39:52 +0900
commit5cde13f21d36c7224b0e13d11c4b49379ae5210d (patch)
treee8269ac85a4b0f7d416e2565fa4f451b5cb41351 /boost/hana/scan_right.hpp
parentd9ec475d945d3035377a0d89ed42e382d8988891 (diff)
downloadboost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.gz
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.bz2
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.zip
Imported Upstream version 1.61.0
Change-Id: I96a1f878d1e6164f01e9aadd5147f38fca448d90 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/hana/scan_right.hpp')
-rw-r--r--boost/hana/scan_right.hpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/boost/hana/scan_right.hpp b/boost/hana/scan_right.hpp
new file mode 100644
index 0000000000..3a8a11d435
--- /dev/null
+++ b/boost/hana/scan_right.hpp
@@ -0,0 +1,130 @@
+/*!
+@file
+Defines `boost::hana::scan_right`.
+
+@copyright Louis Dionne 2013-2016
+Distributed under the Boost Software License, Version 1.0.
+(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_HANA_SCAN_RIGHT_HPP
+#define BOOST_HANA_SCAN_RIGHT_HPP
+
+#include <boost/hana/fwd/scan_right.hpp>
+
+#include <boost/hana/at.hpp>
+#include <boost/hana/concept/sequence.hpp>
+#include <boost/hana/config.hpp>
+#include <boost/hana/core/dispatch.hpp>
+#include <boost/hana/core/make.hpp>
+#include <boost/hana/empty.hpp>
+#include <boost/hana/front.hpp>
+#include <boost/hana/length.hpp>
+#include <boost/hana/prepend.hpp>
+
+#include <cstddef>
+#include <utility>
+
+
+BOOST_HANA_NAMESPACE_BEGIN
+ //! @cond
+ template <typename Xs, typename F>
+ constexpr auto scan_right_t::operator()(Xs&& xs, F const& f) const {
+ using S = typename hana::tag_of<Xs>::type;
+ using ScanRight = BOOST_HANA_DISPATCH_IF(scan_right_impl<S>,
+ hana::Sequence<S>::value
+ );
+
+#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
+ static_assert(hana::Sequence<S>::value,
+ "hana::scan_right(xs, f) requires 'xs' to be a Sequence");
+#endif
+
+ return ScanRight::apply(static_cast<Xs&&>(xs), f);
+ }
+
+ template <typename Xs, typename State, typename F>
+ constexpr auto scan_right_t::operator()(Xs&& xs, State&& state, F const& f) const {
+ using S = typename hana::tag_of<Xs>::type;
+ using ScanRight = BOOST_HANA_DISPATCH_IF(scan_right_impl<S>,
+ hana::Sequence<S>::value
+ );
+
+#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
+ static_assert(hana::Sequence<S>::value,
+ "hana::scan_right(xs, state, f) requires 'xs' to be a Sequence");
+#endif
+
+ return ScanRight::apply(static_cast<Xs&&>(xs),
+ static_cast<State&&>(state), f);
+ }
+ //! @endcond
+
+ template <typename S, bool condition>
+ struct scan_right_impl<S, when<condition>> : default_ {
+ // Without initial state
+ template <typename Xs, typename F, std::size_t n1, std::size_t n2, std::size_t ...ns>
+ static constexpr auto
+ apply1_impl(Xs&& xs, F const& f, std::index_sequence<n1, n2, ns...>) {
+ auto rest = scan_right_impl::apply1_impl(static_cast<Xs&&>(xs),
+ f, std::index_sequence<n2, ns...>{});
+ auto element = f(hana::at_c<n1>(static_cast<Xs&&>(xs)), hana::front(rest));
+ return hana::prepend(std::move(rest), std::move(element));
+ }
+
+ template <typename Xs, typename F, std::size_t n>
+ static constexpr auto apply1_impl(Xs&& xs, F const&, std::index_sequence<n>) {
+ return hana::make<S>(hana::at_c<n>(static_cast<Xs&&>(xs)));
+ }
+
+ template <typename Xs, typename F>
+ static constexpr auto apply1_impl(Xs&&, F const&, std::index_sequence<>) {
+ return hana::empty<S>();
+ }
+
+ template <typename Xs, typename F>
+ static constexpr auto apply(Xs&& xs, F const& f) {
+ constexpr std::size_t Len = decltype(hana::length(xs))::value;
+ return scan_right_impl::apply1_impl(static_cast<Xs&&>(xs),
+ f, std::make_index_sequence<Len>{});
+ }
+
+
+ // With initial state
+ template <typename Xs, typename State, typename F,
+ std::size_t n1, std::size_t n2, std::size_t ...ns>
+ static constexpr auto
+ apply_impl(Xs&& xs, State&& state, F const& f,
+ std::index_sequence<n1, n2, ns...>)
+ {
+ auto rest = scan_right_impl::apply_impl(static_cast<Xs&&>(xs),
+ static_cast<State&&>(state),
+ f, std::index_sequence<n2, ns...>{});
+ auto element = f(hana::at_c<n1>(static_cast<Xs&&>(xs)), hana::front(rest));
+ return hana::prepend(std::move(rest), std::move(element));
+ }
+
+ template <typename Xs, typename State, typename F, std::size_t n>
+ static constexpr auto
+ apply_impl(Xs&& xs, State&& state, F const& f, std::index_sequence<n>) {
+ auto element = f(hana::at_c<n>(static_cast<Xs&&>(xs)), state);
+ return hana::make<S>(std::move(element), static_cast<State&&>(state));
+ }
+
+ template <typename Xs, typename State, typename F>
+ static constexpr auto
+ apply_impl(Xs&&, State&& state, F const&, std::index_sequence<>) {
+ return hana::make<S>(static_cast<State&&>(state));
+ }
+
+ template <typename Xs, typename State, typename F>
+ static constexpr auto apply(Xs&& xs, State&& state, F const& f) {
+ constexpr std::size_t Len = decltype(hana::length(xs))::value;
+ return scan_right_impl::apply_impl(static_cast<Xs&&>(xs),
+ static_cast<State&&>(state),
+ f, std::make_index_sequence<Len>{});
+ }
+ };
+BOOST_HANA_NAMESPACE_END
+
+#endif // !BOOST_HANA_SCAN_RIGHT_HPP