dynamic_array.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2012 John Maddock.
  3. // Copyright Christopher Kormanyos 2013. 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_DYNAMIC_ARRAY_HPP
  8. #define BOOST_MP_DETAIL_DYNAMIC_ARRAY_HPP
  9. #include <algorithm>
  10. #include <cstddef>
  11. #include <cstdint>
  12. #include <vector>
  13. #include <boost/multiprecision/detail/rebind.hpp>
  14. namespace boost { namespace multiprecision { namespace backends { namespace detail {
  15. template <class ValueType, const std::uint32_t ElemNumber, class my_allocator>
  16. struct dynamic_array : public std::vector<ValueType, typename rebind<ValueType, my_allocator>::type>
  17. {
  18. private:
  19. using base_class_type = std::vector<ValueType, typename rebind<ValueType, my_allocator>::type>;
  20. public:
  21. dynamic_array()
  22. : base_class_type(static_cast<typename base_class_type::size_type>(ElemNumber),
  23. static_cast<typename base_class_type::value_type>(0u)) { }
  24. dynamic_array(std::initializer_list<std::uint32_t> lst)
  25. : base_class_type(static_cast<typename base_class_type::size_type>(ElemNumber),
  26. static_cast<typename base_class_type::value_type>(0u))
  27. {
  28. std::copy(lst.begin(),
  29. lst.begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
  30. data());
  31. }
  32. typename base_class_type::value_type* data() { return &(*(this->begin())); }
  33. const typename base_class_type::value_type* data() const { return &(*(this->begin())); }
  34. };
  35. }}}} // namespace boost::multiprecision::backends::detail
  36. #endif // BOOST_MP_DETAIL_DYNAMIC_ARRAY_HPP