6 #include <boost/any.hpp>
18 array(const array<std::uint8_t>&);
19 array& operator=(const array<std::uint8_t>&);
21 template<typename> friend class array;
29 explicit array(std::uint8_t* ptr, std::size_t size, bool cacheable, T2&& storage)
32 , cacheable_(cacheable)
33 , storage_(new boost::any(std::forward<T2>(storage)))
40 , cacheable_(other.cacheable_)
41 , storage_(std::move(other.storage_))
43 CASPAR_ASSERT(storage_);
48 array& operator=(array&& other)
50 std::swap(ptr_, other.ptr_);
51 std::swap(size_, other.size_);
52 std::swap(storage_, other.storage_);
53 std::swap(cacheable_, other.cacheable_);
55 CASPAR_ASSERT(storage_);
62 T* begin() const {return ptr_;}
63 T* data() const {return ptr_;}
64 T* end() const {return reinterpret_cast<T*>(reinterpret_cast<char*>(ptr_) + size_);}
65 std::size_t size() const {return size_;}
66 bool empty() const {return size() == 0;}
67 bool cacheable() const {return cacheable_;}
72 return boost::any_cast<T2>(storage_.get());
78 std::unique_ptr<boost::any> storage_;
82 class array<const T> final
89 array() = default; // Needed by std::future
92 explicit array(const std::uint8_t* ptr, std::size_t size, bool cacheable, T2&& storage)
95 , cacheable_(cacheable)
96 , storage_(new boost::any(std::forward<T2>(storage)))
100 explicit array(const std::uint8_t* ptr, std::size_t size, bool cacheable)
103 , cacheable_(cacheable)
104 , storage_(new boost::any)
108 array(const array& other)
111 , cacheable_(other.cacheable_)
112 , storage_(other.storage_)
114 CASPAR_ASSERT(storage_);
117 array(array<T>&& other)
120 , cacheable_(other.cacheable_)
121 , storage_(std::move(other.storage_))
123 CASPAR_ASSERT(storage_);
128 array& operator=(array other)
134 void swap(array& other)
136 std::swap(ptr_, other.ptr_);
137 std::swap(size_, other.size_);
138 std::swap(storage_, other.storage_);
139 std::swap(cacheable_, other.cacheable_);
144 const T* begin() const {return ptr_;}
145 const T* data() const {return ptr_;}
146 const T* end() const {return reinterpret_cast<const T*>(reinterpret_cast<const char*>(ptr_) + size_);}
147 std::size_t size() const {return size_;}
148 bool empty() const {return size() == 0;}
149 bool cacheable() const {return cacheable_;}
151 template<typename T2>
154 return boost::any_cast<T2>(storage_.get());
158 const T* ptr_ = nullptr;
159 std::size_t size_ = 0;
160 bool cacheable_ = false;
161 std::shared_ptr<boost::any> storage_;
169 void swap(caspar::array<const T>& lhs, caspar::array<const T>& rhs)