File indexing completed on 2025-01-18 09:38:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_LENGTH_HPP
0011 #define BOOST_HANA_LENGTH_HPP
0012
0013 #include <boost/hana/fwd/length.hpp>
0014
0015 #include <boost/hana/concept/foldable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/integral_constant.hpp>
0019 #include <boost/hana/unpack.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023
0024 template <typename Xs>
0025 constexpr auto length_t::operator()(Xs const& xs) const {
0026 using S = typename hana::tag_of<Xs>::type;
0027 using Length = BOOST_HANA_DISPATCH_IF(length_impl<S>,
0028 hana::Foldable<S>::value
0029 );
0030
0031 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032 static_assert(hana::Foldable<S>::value,
0033 "hana::length(xs) requires 'xs' to be Foldable");
0034 #endif
0035
0036 return Length::apply(xs);
0037 }
0038
0039
0040 namespace detail {
0041 struct argn {
0042 template <typename ...Xs>
0043 constexpr hana::size_t<sizeof...(Xs)> operator()(Xs const& ...) const
0044 { return {}; }
0045 };
0046 }
0047
0048 template <typename T, bool condition>
0049 struct length_impl<T, when<condition>> : default_ {
0050 template <typename Xs>
0051 static constexpr auto apply(Xs const& xs) {
0052 return hana::unpack(xs, detail::argn{});
0053 }
0054 };
0055 }}
0056
0057 #endif