storage_traits.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // The authors gratefully acknowledge the support of
  9. // Fraunhofer IOSB, Ettlingen Germany
  10. //
  11. #ifndef _BOOST_STORAGE_TRAITS_HPP_
  12. #define _BOOST_STORAGE_TRAITS_HPP_
  13. #include <vector>
  14. #include <array>
  15. namespace boost {
  16. namespace numeric {
  17. namespace ublas {
  18. template <class A>
  19. struct storage_traits;
  20. template <class V, class A>
  21. struct storage_traits<std::vector<V,A>>
  22. {
  23. using array_type = std::vector<V,A>;
  24. using size_type = typename array_type::size_type;
  25. using difference_type = typename array_type::difference_type;
  26. using value_type = typename array_type::value_type;
  27. using reference = typename array_type::reference;
  28. using const_reference = typename array_type::const_reference;
  29. using pointer = typename array_type::pointer;
  30. using const_pointer = typename array_type::const_pointer;
  31. using iterator = typename array_type::iterator;
  32. using const_iterator = typename array_type::const_iterator;
  33. using reverse_iterator = typename array_type::reverse_iterator;
  34. using const_reverse_iterator = typename array_type::const_reverse_iterator;
  35. template<class U>
  36. using rebind = std::vector<U, typename std::allocator_traits<A>::template rebind_alloc<U>>;
  37. };
  38. template <class V, std::size_t N>
  39. struct storage_traits<std::array<V,N>>
  40. {
  41. using array_type = std::array<V,N>;
  42. using size_type = typename array_type::size_type;
  43. using difference_type = typename array_type::difference_type;
  44. using value_type = typename array_type::value_type;
  45. using reference = typename array_type::reference;
  46. using const_reference = typename array_type::const_reference;
  47. using pointer = typename array_type::pointer;
  48. using const_pointer = typename array_type::const_pointer;
  49. using iterator = typename array_type::iterator;
  50. using const_iterator = typename array_type::const_iterator;
  51. using reverse_iterator = typename array_type::reverse_iterator;
  52. using const_reverse_iterator = typename array_type::const_reverse_iterator;
  53. template<class U>
  54. using rebind = std::array<U,N>;
  55. };
  56. } // ublas
  57. } // numeric
  58. } // boost
  59. #endif // _BOOST_STORAGE_TRAITS_HPP_