2019-07-10 09:35:51 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2019 ARM Limited
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef __array
|
|
|
|
#define __array
|
|
|
|
|
|
|
|
#include <initializer_list> // required by standard
|
|
|
|
|
|
|
|
#include <cstddef> // size_t, ptrdiff_t
|
|
|
|
#include <algorithm> // fill and swap_ranges
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <typename>
|
|
|
|
struct reverse_iterator;
|
|
|
|
|
|
|
|
// [array]
|
|
|
|
template <typename _TypeT, size_t _Size>
|
|
|
|
struct array {
|
|
|
|
// [array.overview]
|
2019-07-19 14:17:07 +00:00
|
|
|
_TypeT _C_elem[_Size != 0 ? _Size : 1];
|
2019-07-10 09:35:51 +00:00
|
|
|
|
|
|
|
using value_type = _TypeT;
|
|
|
|
using size_type = size_t;
|
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using reference = _TypeT &;
|
|
|
|
using const_reference = const _TypeT &;
|
|
|
|
using pointer = _TypeT *;
|
|
|
|
using const_pointer = const _TypeT *;
|
|
|
|
using iterator = _TypeT *;
|
|
|
|
using const_iterator = const _TypeT *;
|
|
|
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
|
|
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
|
|
|
// [array.size]
|
|
|
|
constexpr size_type size() const noexcept
|
|
|
|
{
|
|
|
|
return _Size;
|
|
|
|
}
|
|
|
|
// [array.data]
|
|
|
|
_TypeT *data() noexcept
|
|
|
|
{
|
|
|
|
return _C_elem;
|
|
|
|
}
|
|
|
|
const _TypeT *data() const noexcept
|
|
|
|
{
|
|
|
|
return _C_elem;
|
|
|
|
}
|
|
|
|
// [array.fill]
|
|
|
|
void fill(const _TypeT &value)
|
|
|
|
{
|
|
|
|
std::fill(begin(), end(), value);
|
|
|
|
}
|
|
|
|
// [array.swap]
|
|
|
|
void swap(array &__y)
|
|
|
|
{
|
|
|
|
std::swap_ranges(begin(), end(), __y.begin());
|
|
|
|
}
|
|
|
|
_TypeT &at(size_t pos)
|
|
|
|
{
|
|
|
|
MBED_ASSERT(pos < size());
|
|
|
|
return _C_elem[pos];
|
|
|
|
}
|
|
|
|
const _TypeT &at(size_t pos) const
|
|
|
|
{
|
|
|
|
MBED_ASSERT(pos < size());
|
|
|
|
return _C_elem[pos];
|
|
|
|
}
|
|
|
|
_TypeT &operator[](size_t pos)
|
|
|
|
{
|
|
|
|
return _C_elem[pos];
|
|
|
|
}
|
|
|
|
const _TypeT &operator[](size_t pos) const
|
|
|
|
{
|
|
|
|
return _C_elem[pos];
|
|
|
|
}
|
|
|
|
_TypeT &front()
|
|
|
|
{
|
|
|
|
return _C_elem[0];
|
|
|
|
}
|
|
|
|
const _TypeT &front() const
|
|
|
|
{
|
|
|
|
return _C_elem[0];
|
|
|
|
}
|
|
|
|
_TypeT &back()
|
|
|
|
{
|
|
|
|
return _C_elem[_Size - 1];
|
|
|
|
}
|
|
|
|
const _TypeT &back() const
|
|
|
|
{
|
|
|
|
return _C_elem[_Size - 1];
|
|
|
|
}
|
|
|
|
constexpr bool empty() const noexcept
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
constexpr size_type max_size() const noexcept
|
|
|
|
{
|
|
|
|
return _Size;
|
|
|
|
}
|
|
|
|
iterator begin() noexcept
|
|
|
|
{
|
|
|
|
return _C_elem;
|
|
|
|
}
|
|
|
|
const_iterator begin() const noexcept
|
|
|
|
{
|
|
|
|
return _C_elem;
|
|
|
|
}
|
|
|
|
const_iterator cbegin() const noexcept
|
|
|
|
{
|
|
|
|
return _C_elem;
|
|
|
|
}
|
|
|
|
iterator end() noexcept
|
|
|
|
{
|
|
|
|
return _C_elem + _Size;
|
|
|
|
}
|
|
|
|
const_iterator end() const noexcept
|
|
|
|
{
|
|
|
|
return _C_elem + _Size;
|
|
|
|
}
|
|
|
|
const_iterator cend() const noexcept
|
|
|
|
{
|
|
|
|
return _C_elem + _Size;
|
|
|
|
}
|
|
|
|
reverse_iterator rbegin() noexcept
|
|
|
|
{
|
|
|
|
return reverse_iterator(end());
|
|
|
|
}
|
|
|
|
const_reverse_iterator rbegin() const noexcept
|
|
|
|
{
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
}
|
|
|
|
const_reverse_iterator crbegin() const noexcept
|
|
|
|
{
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
}
|
|
|
|
reverse_iterator rend() noexcept
|
|
|
|
{
|
|
|
|
return reverse_iterator(begin());
|
|
|
|
}
|
|
|
|
const_reverse_iterator rend() const noexcept
|
|
|
|
{
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
}
|
|
|
|
const_reverse_iterator crend() const noexcept
|
|
|
|
{
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// [array.special]
|
|
|
|
template <class _TypeT, size_t _Size>
|
|
|
|
void swap(array<_TypeT, _Size> &__x, array<_TypeT, _Size> &__y)
|
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
#endif /* __array */
|