2 // Copyright (c) 2016 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
25 #include "meta_utils.hpp"
29 /// @addtogroup cpp_api C++ API
34 /// @defgroup cpp_helpers Helpers
38 class mutable_array_ref {
40 typedef size_t size_type;
42 mutable_array_ref() : _data(nullptr), _size(0) {}
43 explicit mutable_array_ref(T& val) : _data(&val), _size(1) {}
44 mutable_array_ref(T* data, size_t size) : _data(data), _size(size) {}
47 explicit mutable_array_ref(T (&arr)[N]) : _data(arr), _size(N) {}
49 mutable_array_ref(const mutable_array_ref& other) : _data(other._data), _size(other._size) {}
51 mutable_array_ref& operator=(const mutable_array_ref& other) {
59 T* data() const { return _data; }
60 size_t size() const { return _size; }
61 bool empty() const { return _size == 0; }
63 #if defined(_SECURE_SCL) && (_SECURE_SCL > 0)
64 typedef stdext::checked_array_iterator<T*> iterator;
65 typedef stdext::checked_array_iterator<const T*> const_iterator;
66 iterator begin() const { return stdext::make_checked_array_iterator(_data, _size); }
67 iterator end() const { return stdext::make_checked_array_iterator(_data, _size, _size); }
68 const_iterator cbegin() const { return stdext::make_checked_array_iterator(_data, _size); }
69 const_iterator cend() const { return stdext::make_checked_array_iterator(_data, _size, _size); }
72 typedef T* const_iterator;
73 iterator begin() const { return _data; }
74 iterator end() const { return _data + _size; }
75 const_iterator cbegin() const { return _data; }
76 const_iterator cend() const { return _data + _size; }
79 T& operator[](size_t idx) const {
84 T& at(size_t idx) const {
85 if (idx >= _size) throw std::out_of_range("idx");
89 std::vector<T> vector() const { return std::vector<T>(_data, _data + _size); }