| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::length`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 6 | Distributed under the Boost Software License, Version 1.0. |
| 7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_FWD_LENGTH_HPP |
| 11 | #define BOOST_HANA_FWD_LENGTH_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | #include <boost/hana/core/when.hpp> |
| 15 | |
| 16 | |
| 17 | namespace boost { namespace hana { |
| 18 | //! Return the number of elements in a foldable structure. |
| 19 | //! @ingroup group-Foldable |
| 20 | //! |
| 21 | //! Given a `Foldable` `xs`, `length(xs)` must return an object of an |
| 22 | //! unsigned integral type, or an `IntegralConstant` holding such an |
| 23 | //! object, which represents the number of elements in the structure. |
| 24 | //! |
| 25 | //! @note |
| 26 | //! Since only compile-time `Foldable`s are supported in the library |
| 27 | //! right now, `length` must always return an `IntegralConstant`. |
| 28 | //! |
| 29 | //! |
| 30 | //! Example |
| 31 | //! ------- |
| 32 | //! @include example/length.cpp |
| 33 | #ifdef BOOST_HANA_DOXYGEN_INVOKED |
| 34 | constexpr auto length = [](auto const& xs) { |
| 35 | return tag-dispatched; |
| 36 | }; |
| 37 | #else |
| 38 | template <typename T, typename = void> |
| 39 | struct length_impl : length_impl<T, when<true>> { }; |
| 40 | |
| 41 | struct length_t { |
| 42 | template <typename Xs> |
| 43 | constexpr auto operator()(Xs const& xs) const; |
| 44 | }; |
| 45 | |
| 46 | BOOST_HANA_INLINE_VARIABLE constexpr length_t length{}; |
| 47 | #endif |
| 48 | }} // end namespace boost::hana |
| 49 | |
| 50 | #endif // !BOOST_HANA_FWD_LENGTH_HPP |
| 51 | |