summaryrefslogtreecommitdiff
path: root/boost/hana/length.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/hana/length.hpp')
-rw-r--r--boost/hana/length.hpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/boost/hana/length.hpp b/boost/hana/length.hpp
new file mode 100644
index 0000000000..c7224df9bd
--- /dev/null
+++ b/boost/hana/length.hpp
@@ -0,0 +1,57 @@
+/*!
+@file
+Defines `boost::hana::length`.
+
+@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_LENGTH_HPP
+#define BOOST_HANA_LENGTH_HPP
+
+#include <boost/hana/fwd/length.hpp>
+
+#include <boost/hana/concept/foldable.hpp>
+#include <boost/hana/config.hpp>
+#include <boost/hana/core/dispatch.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/unpack.hpp>
+
+
+BOOST_HANA_NAMESPACE_BEGIN
+ //! @cond
+ template <typename Xs>
+ constexpr auto length_t::operator()(Xs const& xs) const {
+ using S = typename hana::tag_of<Xs>::type;
+ using Length = BOOST_HANA_DISPATCH_IF(length_impl<S>,
+ hana::Foldable<S>::value
+ );
+
+ #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
+ static_assert(hana::Foldable<S>::value,
+ "hana::length(xs) requires 'xs' to be Foldable");
+ #endif
+
+ return Length::apply(xs);
+ }
+ //! @endcond
+
+ namespace detail {
+ struct argn {
+ template <typename ...Xs>
+ constexpr auto operator()(Xs const& ...) const
+ { return hana::size_c<sizeof...(Xs)>; }
+ };
+ }
+
+ template <typename T, bool condition>
+ struct length_impl<T, when<condition>> : default_ {
+ template <typename Xs>
+ static constexpr auto apply(Xs const& xs) {
+ return hana::unpack(xs, detail::argn{});
+ }
+ };
+BOOST_HANA_NAMESPACE_END
+
+#endif // !BOOST_HANA_LENGTH_HPP