| 147 | |
| 148 | template <typename T, std::size_t N> |
| 149 | struct array_back_insert_iterator : public std::back_insert_iterator<std::array<T, N>> { |
| 150 | typedef std::back_insert_iterator<std::array<T, N>> base_type; |
| 151 | explicit array_back_insert_iterator(std::array<T, N>& arr) |
| 152 | : base_type(arr) |
| 153 | , arr_ptr_(&arr) |
| 154 | , pos_(0) |
| 155 | { |
| 156 | } |
| 157 | array_back_insert_iterator(const array_back_insert_iterator<T, N>& other) |
| 158 | : base_type(*other.arr_ptr_) |
| 159 | , arr_ptr_(other.arr_ptr_) |
| 160 | , pos_(other.pos_) |
| 161 | { |
| 162 | } |
| 163 | array_back_insert_iterator<T, N>& operator=(const array_back_insert_iterator<T, N>& other) |
| 164 | { |
| 165 | arr_ptr_ = other.arr_ptr_; |
| 166 | pos_ = other.pos_; |
| 167 | return *this; |
| 168 | } |
| 169 | ~array_back_insert_iterator() |
| 170 | { |
| 171 | assert(pos_ == 0 || pos_ == N); |
| 172 | } |
| 173 | array_back_insert_iterator<T, N>& operator=(const T& x) |
| 174 | { |
| 175 | assert(pos_ < N); |
| 176 | (*arr_ptr_)[pos_] = x; |
| 177 | ++pos_; |
| 178 | return *this; |
| 179 | } |
| 180 | array_back_insert_iterator<T, N>& operator=(T&& x) |
| 181 | { |
| 182 | assert(pos_ < N); |
| 183 | assign((*arr_ptr_)[pos_], std::move(x)); |
| 184 | ++pos_; |
| 185 | return *this; |
| 186 | } |
| 187 | array_back_insert_iterator<T, N>& operator*() { return *this; } |
| 188 | array_back_insert_iterator<T, N>& operator++() { return *this; } |
| 189 | array_back_insert_iterator<T, N> operator++(int) { return *this; } |
| 190 | |
| 191 | private: |
| 192 | std::array<T, N>* arr_ptr_; |
| 193 | std::size_t pos_; |
| 194 | }; |
| 195 | |
| 196 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 1915 |
| 197 | template <typename T, std::size_t N> |