tuple_size.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2016-2025 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. #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT)
  10. #include <boost/pfr/detail/sequence_tuple.hpp>
  11. #include <boost/pfr/detail/fields_count.hpp>
  12. #if !defined(BOOST_PFR_INTERFACE_UNIT)
  13. #include <type_traits>
  14. #include <utility> // metaprogramming stuff
  15. #endif
  16. /// \file boost/pfr/tuple_size.hpp
  17. /// Contains tuple-like interfaces to get fields count \forcedlink{tuple_size}, \forcedlink{tuple_size_v}.
  18. ///
  19. /// \b Synopsis:
  20. namespace boost { namespace pfr {
  21. BOOST_PFR_BEGIN_MODULE_EXPORT
  22. /// Has a static const member variable `value` that contains fields count in a T.
  23. /// Works for any T that satisfies \aggregate.
  24. ///
  25. /// \b Example:
  26. /// \code
  27. /// std::array<int, boost::pfr::tuple_size<my_structure>::value > a;
  28. /// \endcode
  29. template <class T>
  30. using tuple_size = detail::size_t_< boost::pfr::detail::fields_count<T>() >;
  31. /// `tuple_size_v` is a template variable that contains fields count in a T and
  32. /// works for any T that satisfies \aggregate.
  33. ///
  34. /// \b Example:
  35. /// \code
  36. /// std::array<int, boost::pfr::tuple_size_v<my_structure> > a;
  37. /// \endcode
  38. template <class T>
  39. constexpr std::size_t tuple_size_v = tuple_size<T>::value;
  40. BOOST_PFR_END_MODULE_EXPORT
  41. }} // namespace boost::pfr
  42. #endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT)
  43. #endif // BOOST_PFR_TUPLE_SIZE_HPP