6 #include <boost/any.hpp>
18 array(const array<T>&);
19 array& operator=(const array<T>&);
21 template<typename> friend class array;
24 // Boost Range support
27 typedef const T* const_iterator;
34 explicit array(T* ptr, std::size_t size, bool cacheable, T2&& storage)
37 , cacheable_(cacheable)
38 , storage_(new boost::any(std::forward<T2>(storage)))
45 , cacheable_(other.cacheable_)
46 , storage_(std::move(other.storage_))
48 CASPAR_ASSERT(storage_);
53 array& operator=(array&& other)
55 std::swap(ptr_, other.ptr_);
56 std::swap(size_, other.size_);
57 std::swap(storage_, other.storage_);
58 std::swap(cacheable_, other.cacheable_);
60 CASPAR_ASSERT(storage_);
67 T* begin() const {return ptr_;}
68 T* data() const {return ptr_;}
69 T* end() const {return ptr_ + size_;}
70 std::size_t size() const {return size_;}
71 bool empty() const {return size() == 0;}
72 bool cacheable() const {return cacheable_;}
77 return boost::any_cast<T2>(storage_.get());
83 std::unique_ptr<boost::any> storage_;
87 class array<const T> final
91 // Boost Range support
93 typedef const T* iterator;
94 typedef const T* const_iterator;
99 array() = default; // Needed by std::future
101 template<typename T2>
102 explicit array(const T* ptr, std::size_t size, bool cacheable, T2&& storage)
105 , cacheable_(cacheable)
106 , storage_(new boost::any(std::forward<T2>(storage)))
110 explicit array(const T* ptr, std::size_t size, bool cacheable)
113 , cacheable_(cacheable)
114 , storage_(new boost::any)
118 array(const array& other)
121 , cacheable_(other.cacheable_)
122 , storage_(other.storage_)
124 CASPAR_ASSERT(storage_);
127 array(array<T>&& other)
130 , cacheable_(other.cacheable_)
131 , storage_(std::move(other.storage_))
133 CASPAR_ASSERT(storage_);
138 array& operator=(array other)
144 void swap(array& other)
146 std::swap(ptr_, other.ptr_);
147 std::swap(size_, other.size_);
148 std::swap(storage_, other.storage_);
149 std::swap(cacheable_, other.cacheable_);
154 const T* begin() const {return ptr_;}
155 const T* data() const {return ptr_;}
156 const T* end() const {return ptr_ + size_;}
157 std::size_t size() const {return size_;}
158 bool empty() const {return size() == 0;}
159 bool cacheable() const {return cacheable_;}
161 template<typename T2>
164 return boost::any_cast<T2>(storage_.get());
168 const T* ptr_ = nullptr;
169 std::size_t size_ = 0;
170 bool cacheable_ = false;
171 std::shared_ptr<boost::any> storage_;
179 void swap(caspar::array<const T>& lhs, caspar::array<const T>& rhs)