tuple_size.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2016-2024 Antony Polukhin
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PFR_TUPLE_SIZE_HPP
  6. #define BOOST_PFR_TUPLE_SIZE_HPP
  7. #pragma once
  8. #include <boost/pfr/detail/config.hpp>
  9. #include <type_traits>
  10. #include <utility> // metaprogramming stuff
  11. #include <boost/pfr/detail/sequence_tuple.hpp>
  12. #include <boost/pfr/detail/fields_count.hpp>
  13. /// \file boost/pfr/tuple_size.hpp
  14. /// Contains tuple-like interfaces to get fields count \forcedlink{tuple_size}, \forcedlink{tuple_size_v}.
  15. ///
  16. /// \b Synopsis:
  17. namespace boost { namespace pfr {
  18. /// Has a static const member variable `value` that contains fields count in a T.
  19. /// Works for any T that satisfies \aggregate.
  20. ///
  21. /// \b Example:
  22. /// \code
  23. /// std::array<int, boost::pfr::tuple_size<my_structure>::value > a;
  24. /// \endcode
  25. template <class T>
  26. using tuple_size = detail::size_t_< boost::pfr::detail::fields_count<T>() >;
  27. /// `tuple_size_v` is a template variable that contains fields count in a T and
  28. /// works for any T that satisfies \aggregate.
  29. ///
  30. /// \b Example:
  31. /// \code
  32. /// std::array<int, boost::pfr::tuple_size_v<my_structure> > a;
  33. /// \endcode
  34. template <class T>
  35. constexpr std::size_t tuple_size_v = tuple_size<T>::value;
  36. }} // namespace boost::pfr
  37. #endif // BOOST_PFR_TUPLE_SIZE_HPP