Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / hana / fwd / length.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::length`.
4
5 @copyright Louis Dionne 2013-2017
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 BOOST_HANA_NAMESPACE_BEGIN
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     constexpr length_t length{};
47 #endif
48 BOOST_HANA_NAMESPACE_END
49
50 #endif // !BOOST_HANA_FWD_LENGTH_HPP