2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- array -----------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_ARRAY
|
|
|
|
#define _LIBCPP_ARRAY
|
|
|
|
|
|
|
|
/*
|
|
|
|
array synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class T, size_t N >
|
2010-05-12 03:42:16 +08:00
|
|
|
struct array
|
2010-08-22 08:02:43 +08:00
|
|
|
{
|
|
|
|
// types:
|
|
|
|
typedef T & reference;
|
|
|
|
typedef const T & const_reference;
|
|
|
|
typedef implementation defined iterator;
|
|
|
|
typedef implementation defined const_iterator;
|
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef T value_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef T* pointer;
|
|
|
|
typedef const T* const_pointer;
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// No explicit construct/copy/destroy for aggregate type
|
|
|
|
void fill(const T& u);
|
2016-04-22 07:38:59 +08:00
|
|
|
void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// iterators:
|
2011-06-01 05:06:33 +08:00
|
|
|
iterator begin() noexcept;
|
|
|
|
const_iterator begin() const noexcept;
|
|
|
|
iterator end() noexcept;
|
|
|
|
const_iterator end() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-01 05:06:33 +08:00
|
|
|
reverse_iterator rbegin() noexcept;
|
|
|
|
const_reverse_iterator rbegin() const noexcept;
|
|
|
|
reverse_iterator rend() noexcept;
|
|
|
|
const_reverse_iterator rend() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-01 05:06:33 +08:00
|
|
|
const_iterator cbegin() const noexcept;
|
|
|
|
const_iterator cend() const noexcept;
|
|
|
|
const_reverse_iterator crbegin() const noexcept;
|
|
|
|
const_reverse_iterator crend() const noexcept;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
|
|
|
// capacity:
|
2011-06-01 05:06:33 +08:00
|
|
|
constexpr size_type size() const noexcept;
|
|
|
|
constexpr size_type max_size() const noexcept;
|
2012-07-21 03:20:49 +08:00
|
|
|
constexpr bool empty() const noexcept;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
|
|
|
// element access:
|
|
|
|
reference operator[](size_type n);
|
2013-07-18 02:25:36 +08:00
|
|
|
const_reference operator[](size_type n) const; // constexpr in C++14
|
|
|
|
const_reference at(size_type n) const; // constexpr in C++14
|
2010-08-22 08:02:43 +08:00
|
|
|
reference at(size_type n);
|
|
|
|
|
|
|
|
reference front();
|
2013-07-18 02:25:36 +08:00
|
|
|
const_reference front() const; // constexpr in C++14
|
2010-08-22 08:02:43 +08:00
|
|
|
reference back();
|
2013-07-18 02:25:36 +08:00
|
|
|
const_reference back() const; // constexpr in C++14
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2011-06-01 05:06:33 +08:00
|
|
|
T* data() noexcept;
|
|
|
|
const T* data() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2018-05-19 05:01:04 +08:00
|
|
|
template <class T, class... U>
|
|
|
|
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator==(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator!=(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator<(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator>(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator<=(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
template <class T, size_t N>
|
|
|
|
bool operator>=(const array<T,N>& x, const array<T,N>& y);
|
|
|
|
|
|
|
|
template <class T, size_t N >
|
2018-05-19 05:01:04 +08:00
|
|
|
void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2019-01-12 05:57:12 +08:00
|
|
|
template <class T> struct tuple_size;
|
2019-04-02 00:39:34 +08:00
|
|
|
template <size_t I, class T> struct tuple_element;
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class T, size_t N> struct tuple_size<array<T, N>>;
|
2015-11-20 03:41:04 +08:00
|
|
|
template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
|
|
|
|
template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
|
|
|
|
template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
|
|
|
|
template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
|
2015-12-18 08:36:55 +08:00
|
|
|
template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <__tuple>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
2018-02-08 05:06:13 +08:00
|
|
|
#include <cstdlib> // for _LIBCPP_UNREACHABLE
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2018-02-08 05:06:13 +08:00
|
|
|
#include <__debug>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2018-02-08 05:06:13 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2017-01-05 07:56:00 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS array
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
// types:
|
|
|
|
typedef array __self;
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef value_type* iterator;
|
|
|
|
typedef const value_type* const_iterator;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef const value_type* const_pointer;
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-02-08 05:06:13 +08:00
|
|
|
_Tp __elems_[_Size];
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// No explicit construct/copy/destroy for aggregate type
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
|
|
|
|
_VSTD::fill_n(__elems_, _Size, __u);
|
|
|
|
}
|
2018-02-06 11:03:37 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-02-08 05:06:13 +08:00
|
|
|
void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
|
|
|
|
std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// iterators:
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-08 05:06:13 +08:00
|
|
|
iterator begin() _NOEXCEPT {return iterator(data());}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-08 05:06:13 +08:00
|
|
|
const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-08 05:06:13 +08:00
|
|
|
iterator end() _NOEXCEPT {return iterator(data() + _Size);}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-08 05:06:13 +08:00
|
|
|
const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
|
2011-06-01 05:06:33 +08:00
|
|
|
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
|
|
|
|
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_iterator cbegin() const _NOEXCEPT {return begin();}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_iterator cend() const _NOEXCEPT {return end();}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2011-06-01 05:06:33 +08:00
|
|
|
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// capacity:
|
2011-06-01 05:06:33 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 03:20:49 +08:00
|
|
|
_LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
|
2011-06-01 05:06:33 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 03:20:49 +08:00
|
|
|
_LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
|
2017-11-15 13:51:26 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
// element access:
|
2017-01-16 11:02:10 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2019-03-15 05:56:57 +08:00
|
|
|
reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];}
|
2017-01-16 11:02:10 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2019-03-15 05:56:57 +08:00
|
|
|
const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
|
2017-01-16 11:02:10 +08:00
|
|
|
|
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-03-19 11:30:07 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-06 11:03:37 +08:00
|
|
|
value_type* data() _NOEXCEPT {return __elems_;}
|
2017-01-05 01:58:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
|
2018-02-06 11:03:37 +08:00
|
|
|
const value_type* data() const _NOEXCEPT {return __elems_;}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2018-02-08 05:06:13 +08:00
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2017-01-16 11:02:10 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX14
|
2010-05-12 03:42:16 +08:00
|
|
|
typename array<_Tp, _Size>::reference
|
|
|
|
array<_Tp, _Size>::at(size_type __n)
|
|
|
|
{
|
|
|
|
if (__n >= _Size)
|
2016-08-25 23:09:01 +08:00
|
|
|
__throw_out_of_range("array::at");
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
return __elems_[__n];
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-07-18 02:25:36 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
typename array<_Tp, _Size>::const_reference
|
|
|
|
array<_Tp, _Size>::at(size_type __n) const
|
|
|
|
{
|
|
|
|
if (__n >= _Size)
|
2016-08-25 23:09:01 +08:00
|
|
|
__throw_out_of_range("array::at");
|
2010-05-12 03:42:16 +08:00
|
|
|
return __elems_[__n];
|
|
|
|
}
|
|
|
|
|
2018-02-08 05:06:13 +08:00
|
|
|
template <class _Tp>
|
|
|
|
struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
|
|
|
|
{
|
|
|
|
// types:
|
|
|
|
typedef array __self;
|
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
typedef value_type* iterator;
|
|
|
|
typedef const value_type* const_iterator;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef const value_type* const_pointer;
|
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
|
|
|
|
typedef typename conditional<is_const<_Tp>::value, const char,
|
|
|
|
char>::type _CharType;
|
2018-02-08 07:50:25 +08:00
|
|
|
|
|
|
|
struct _ArrayInStructT { _Tp __data_[1]; };
|
|
|
|
_ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
|
2018-02-08 05:06:13 +08:00
|
|
|
|
|
|
|
// No explicit construct/copy/destroy for aggregate type
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
|
|
|
|
static_assert(!is_const<_Tp>::value,
|
|
|
|
"cannot fill zero-sized array of type 'const T'");
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void swap(array&) _NOEXCEPT {
|
|
|
|
static_assert(!is_const<_Tp>::value,
|
|
|
|
"cannot swap zero-sized array of type 'const T'");
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterators:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator begin() _NOEXCEPT {return iterator(data());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator end() _NOEXCEPT {return iterator(data());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator end() const _NOEXCEPT {return const_iterator(data());}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator cbegin() const _NOEXCEPT {return begin();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator cend() const _NOEXCEPT {return end();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
|
|
|
|
|
|
|
|
// capacity:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
|
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
|
|
|
_LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
|
|
|
|
|
|
|
|
// element access:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-15 05:56:57 +08:00
|
|
|
reference operator[](size_type) _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2019-03-15 05:56:57 +08:00
|
|
|
const_reference operator[](size_type) const _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
reference at(size_type) {
|
|
|
|
__throw_out_of_range("array<T, 0>::at");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_reference at(size_type) const {
|
|
|
|
__throw_out_of_range("array<T, 0>::at");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-19 11:30:07 +08:00
|
|
|
reference front() _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-19 11:30:07 +08:00
|
|
|
const_reference front() const _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-19 11:30:07 +08:00
|
|
|
reference back() _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-19 11:30:07 +08:00
|
|
|
const_reference back() const _NOEXCEPT {
|
2018-02-08 05:06:13 +08:00
|
|
|
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
|
|
|
|
_LIBCPP_UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-19 05:01:04 +08:00
|
|
|
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
|
|
|
|
template<class _Tp, class... _Args,
|
|
|
|
class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
|
|
|
|
>
|
|
|
|
array(_Tp, _Args...)
|
|
|
|
-> array<_Tp, 1 + sizeof...(_Args)>;
|
|
|
|
#endif
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
2018-02-08 05:06:13 +08:00
|
|
|
return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
2018-02-08 05:06:13 +08:00
|
|
|
return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
|
|
|
|
__y.begin(), __y.end());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2018-08-02 10:11:06 +08:00
|
|
|
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
2010-05-12 03:42:16 +08:00
|
|
|
operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
template <class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-06-02 03:59:32 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2016-04-22 07:38:59 +08:00
|
|
|
_Size == 0 ||
|
2011-06-02 03:59:32 +08:00
|
|
|
__is_swappable<_Tp>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2016-03-08 05:57:10 +08:00
|
|
|
swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
|
2016-04-22 07:38:59 +08:00
|
|
|
_NOEXCEPT_(noexcept(__x.swap(__y)))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, size_t _Size>
|
2019-01-12 05:57:12 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
|
2010-09-22 04:16:37 +08:00
|
|
|
: public integral_constant<size_t, _Size> {};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2019-04-02 00:39:34 +08:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2017-06-12 22:41:37 +08:00
|
|
|
static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef _Tp type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
_Tp&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(array<_Tp, _Size>& __a) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2012-12-19 00:46:30 +08:00
|
|
|
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
|
2013-07-18 02:25:36 +08:00
|
|
|
return __a.__elems_[_Ip];
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-05-12 03:42:16 +08:00
|
|
|
const _Tp&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(const array<_Tp, _Size>& __a) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2012-12-19 00:46:30 +08:00
|
|
|
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
|
2013-07-18 02:25:36 +08:00
|
|
|
return __a.__elems_[_Ip];
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2017-04-16 10:50:40 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-11-18 03:52:17 +08:00
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
2010-11-18 03:52:17 +08:00
|
|
|
_Tp&&
|
2011-06-01 05:06:33 +08:00
|
|
|
get(array<_Tp, _Size>&& __a) _NOEXCEPT
|
2010-11-18 03:52:17 +08:00
|
|
|
{
|
2012-12-19 00:46:30 +08:00
|
|
|
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
|
2013-07-18 02:25:36 +08:00
|
|
|
return _VSTD::move(__a.__elems_[_Ip]);
|
2010-11-18 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
2015-12-18 08:36:55 +08:00
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
|
|
const _Tp&&
|
|
|
|
get(const array<_Tp, _Size>&& __a) _NOEXCEPT
|
|
|
|
{
|
|
|
|
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
|
|
|
|
return _VSTD::move(__a.__elems_[_Ip]);
|
|
|
|
}
|
|
|
|
|
2017-04-16 10:50:40 +08:00
|
|
|
#endif // !_LIBCPP_CXX03_LANG
|
2010-11-18 03:52:17 +08:00
|
|
|
|
2020-01-30 20:27:35 +08:00
|
|
|
#if _LIBCPP_STD_VER > 17
|
|
|
|
|
|
|
|
template <typename _Tp, size_t _Size, size_t... _Index>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
|
|
|
|
__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) {
|
|
|
|
return {{__arr[_Index]...}};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Tp, size_t _Size, size_t... _Index>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
|
|
|
|
__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) {
|
|
|
|
return {{_VSTD::move(__arr[_Index])...}};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
|
|
|
|
to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) {
|
|
|
|
static_assert(
|
|
|
|
!is_array_v<_Tp>,
|
|
|
|
"[array.creation]/1: to_array does not accept multidimensional arrays.");
|
|
|
|
static_assert(
|
|
|
|
is_constructible_v<_Tp, _Tp&>,
|
|
|
|
"[array.creation]/1: to_array requires copy constructible elements.");
|
|
|
|
return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size>
|
|
|
|
to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
|
|
|
|
static_assert(
|
|
|
|
!is_array_v<_Tp>,
|
|
|
|
"[array.creation]/4: to_array does not accept multidimensional arrays.");
|
|
|
|
static_assert(
|
|
|
|
is_move_constructible_v<_Tp>,
|
|
|
|
"[array.creation]/4: to_array requires move constructible elements.");
|
|
|
|
return __to_array_rvalue_impl(_VSTD::move(__arr),
|
|
|
|
make_index_sequence<_Size>());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER > 17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_ARRAY
|