length.hpp 1.4 KB

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