size.hpp 802 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright Matt Borland 2025.
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. *
  7. * See http://www.boost.org for most recent version including documentation.
  8. *
  9. * $Id$
  10. */
  11. #include <iterator>
  12. #include <cstddef>
  13. namespace boost {
  14. namespace random {
  15. namespace detail {
  16. #if defined (__cpp_lib_nonmember_container_access) && __cpp_lib_nonmember_container_access >= 201411L
  17. using std::size;
  18. #else
  19. template <typename C>
  20. constexpr auto size(const C& c) -> decltype(c.size())
  21. {
  22. return c.size();
  23. }
  24. template <typename T, std::size_t N>
  25. constexpr std::size_t size(const T (&)[N]) noexcept
  26. {
  27. return N;
  28. }
  29. #endif
  30. } // namespace detail
  31. } // namespace random
  32. } // namespace boost