stdarray.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2023 Denis Mikhailov
  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_DETAIL_STDARRAY_HPP
  6. #define BOOST_PFR_DETAIL_STDARRAY_HPP
  7. #pragma once
  8. #include <boost/pfr/detail/config.hpp>
  9. #include <utility> // metaprogramming stuff
  10. #include <array>
  11. #include <type_traits> // for std::common_type_t
  12. #include <cstddef>
  13. #include <boost/pfr/detail/sequence_tuple.hpp>
  14. namespace boost { namespace pfr { namespace detail {
  15. template <class... Types>
  16. constexpr auto make_stdarray(const Types&... t) noexcept {
  17. return std::array<std::common_type_t<Types...>, sizeof...(Types)>{t...};
  18. }
  19. template <class T, std::size_t... I>
  20. constexpr auto make_stdarray_from_tietuple(const T& t, std::index_sequence<I...>, int) noexcept {
  21. return detail::make_stdarray(
  22. boost::pfr::detail::sequence_tuple::get<I>(t)...
  23. );
  24. }
  25. template <class T>
  26. constexpr auto make_stdarray_from_tietuple(const T&, std::index_sequence<>, long) noexcept {
  27. return std::array<std::nullptr_t, 0>{};
  28. }
  29. }}} // namespace boost::pfr::detail
  30. #endif // BOOST_PFR_DETAIL_STDARRAY_HPP