constexprify ArrayView
This commit is contained in:
parent
0bbaef6e48
commit
44f81d0b8b
|
@ -15,49 +15,49 @@ class ArrayView
|
|||
public:
|
||||
using size_t = std::size_t;
|
||||
|
||||
ArrayView()
|
||||
constexpr ArrayView()
|
||||
: m_pointer(nullptr), m_size(0) {}
|
||||
|
||||
ArrayView(const T& oneval)
|
||||
constexpr ArrayView(const T& oneval)
|
||||
: m_pointer(&oneval), m_size(1) {}
|
||||
|
||||
ArrayView(const T* pointer, size_t size)
|
||||
constexpr ArrayView(const T* pointer, size_t size)
|
||||
: m_pointer(pointer), m_size(size) {}
|
||||
|
||||
ArrayView(const T* begin, const T* end)
|
||||
constexpr ArrayView(const T* begin, const T* end)
|
||||
: m_pointer(begin), m_size(end - begin) {}
|
||||
|
||||
template<size_t N>
|
||||
ArrayView(const T(&array)[N]) : m_pointer(array), m_size(N) {}
|
||||
constexpr ArrayView(const T(&array)[N]) : m_pointer(array), m_size(N) {}
|
||||
|
||||
template<typename Iterator>
|
||||
ArrayView(const Iterator& begin, const Iterator& end)
|
||||
constexpr ArrayView(const Iterator& begin, const Iterator& end)
|
||||
: m_pointer(&(*begin)), m_size(end - begin) {}
|
||||
|
||||
template<typename Alloc>
|
||||
ArrayView(const std::vector<T, Alloc>& v)
|
||||
constexpr ArrayView(const std::vector<T, Alloc>& v)
|
||||
: m_pointer(&v[0]), m_size(v.size()) {}
|
||||
|
||||
ArrayView(const std::initializer_list<T>& v)
|
||||
constexpr ArrayView(const std::initializer_list<T>& v)
|
||||
: m_pointer(v.begin()), m_size(v.size()) {}
|
||||
|
||||
const T* pointer() const { return m_pointer; }
|
||||
size_t size() const { return m_size; }
|
||||
const T& operator[](size_t n) const { return *(m_pointer + n); }
|
||||
constexpr const T* pointer() const { return m_pointer; }
|
||||
constexpr size_t size() const { return m_size; }
|
||||
constexpr const T& operator[](size_t n) const { return *(m_pointer + n); }
|
||||
|
||||
const T* begin() const { return m_pointer; }
|
||||
const T* end() const { return m_pointer+m_size; }
|
||||
constexpr const T* begin() const { return m_pointer; }
|
||||
constexpr const T* end() const { return m_pointer+m_size; }
|
||||
|
||||
using reverse_iterator = std::reverse_iterator<const T*>;
|
||||
reverse_iterator rbegin() const { return reverse_iterator(m_pointer+m_size); }
|
||||
reverse_iterator rend() const { return reverse_iterator(m_pointer); }
|
||||
constexpr reverse_iterator rbegin() const { return reverse_iterator(m_pointer+m_size); }
|
||||
constexpr reverse_iterator rend() const { return reverse_iterator(m_pointer); }
|
||||
|
||||
const T& front() const { return *m_pointer; }
|
||||
const T& back() const { return *(m_pointer + m_size - 1); }
|
||||
constexpr const T& front() const { return *m_pointer; }
|
||||
constexpr const T& back() const { return *(m_pointer + m_size - 1); }
|
||||
|
||||
bool empty() const { return m_size == 0; }
|
||||
constexpr bool empty() const { return m_size == 0; }
|
||||
|
||||
ArrayView subrange(size_t first, size_t count) const
|
||||
constexpr ArrayView subrange(size_t first, size_t count) const
|
||||
{
|
||||
return ArrayView(m_pointer + first, count);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user