static_array.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2021 John Maddock.
  3. // Copyright Christopher Kormanyos 2021. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MP_DETAIL_STATIC_ARRAY_HPP
  8. #define BOOST_MP_DETAIL_STATIC_ARRAY_HPP
  9. #include <array>
  10. #include <cstddef>
  11. #include <cstdint>
  12. #include <initializer_list>
  13. namespace boost { namespace multiprecision { namespace backends { namespace detail {
  14. template <class ValueType, const std::uint32_t ElemNumber>
  15. struct static_array : public std::array<ValueType, std::size_t(ElemNumber)>
  16. {
  17. private:
  18. using base_class_type = std::array<ValueType, std::size_t(ElemNumber)>;
  19. public:
  20. static_array() noexcept
  21. {
  22. base_class_type::fill(typename base_class_type::value_type(0u));
  23. }
  24. static_array(std::initializer_list<std::uint32_t> lst) noexcept
  25. {
  26. std::copy(lst.begin(),
  27. lst.begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
  28. base_class_type::begin());
  29. std::fill(base_class_type::begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
  30. base_class_type::end(),
  31. typename base_class_type::value_type(0u));
  32. }
  33. };
  34. }}}} // namespace boost::multiprecision::backends::detail
  35. #endif // BOOST_MP_DETAIL_STATIC_ARRAY_HPP