2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- array -----------------------------------===//
|
|
|
|
//
|
2010-05-11 21:36:01 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2010-11-16 22:09:02 +00:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_ARRAY
|
|
|
|
#define _LIBCPP_ARRAY
|
|
|
|
|
|
|
|
/*
|
|
|
|
array synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class T, size_t N >
|
2010-05-11 19:42:16 +00:00
|
|
|
struct array
|
2010-08-22 00:02:43 +00: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-11 19:42:16 +00:00
|
|
|
typedef T* pointer;
|
|
|
|
typedef const T* const_pointer;
|
2010-08-22 00:02:43 +00:00
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// No explicit construct/copy/destroy for aggregate type
|
|
|
|
void fill(const T& u);
|
2011-05-31 21:06:33 +00:00
|
|
|
void swap(array& a) noexcept(noexcept(swap(declval<T&>(), declval<T&>())));
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// iterators:
|
2011-05-31 21:06:33 +00:00
|
|
|
iterator begin() noexcept;
|
|
|
|
const_iterator begin() const noexcept;
|
|
|
|
iterator end() noexcept;
|
|
|
|
const_iterator end() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-31 21:06:33 +00:00
|
|
|
reverse_iterator rbegin() noexcept;
|
|
|
|
const_reverse_iterator rbegin() const noexcept;
|
|
|
|
reverse_iterator rend() noexcept;
|
|
|
|
const_reverse_iterator rend() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-31 21:06:33 +00: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 00:02:43 +00:00
|
|
|
|
|
|
|
// capacity:
|
2011-05-31 21:06:33 +00:00
|
|
|
constexpr size_type size() const noexcept;
|
|
|
|
constexpr size_type max_size() const noexcept;
|
|
|
|
bool empty() const noexcept;
|
2010-08-22 00:02:43 +00:00
|
|
|
|
|
|
|
// element access:
|
|
|
|
reference operator[](size_type n);
|
|
|
|
const_reference operator[](size_type n) const;
|
|
|
|
const_reference at(size_type n) const;
|
|
|
|
reference at(size_type n);
|
|
|
|
|
|
|
|
reference front();
|
|
|
|
const_reference front() const;
|
|
|
|
reference back();
|
|
|
|
const_reference back() const;
|
|
|
|
|
2011-05-31 21:06:33 +00:00
|
|
|
T* data() noexcept;
|
|
|
|
const T* data() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2010-08-22 00:02:43 +00: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 >
|
2011-05-31 21:06:33 +00:00
|
|
|
void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
|
2010-08-22 00:02:43 +00:00
|
|
|
|
|
|
|
template <class T> class tuple_size;
|
|
|
|
template <int I, class T> class tuple_element;
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T, size_t N> struct tuple_size<array<T, N>>;
|
2010-08-22 00:02:43 +00:00
|
|
|
template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>;
|
2011-05-31 21:06:33 +00:00
|
|
|
template <int I, class T, size_t N> T& get(array<T, N>&) noexcept;
|
|
|
|
template <int I, class T, size_t N> const T& get(const array<T, N>&) noexcept;
|
|
|
|
template <int I, class T, size_t N> T&& get(array<T, N>&&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <__tuple>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
#if defined(_LIBCPP_NO_EXCEPTIONS)
|
|
|
|
#include <cassert>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma GCC system_header
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-09-21 20:16:37 +00:00
|
|
|
struct _LIBCPP_VISIBLE array
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
// types:
|
|
|
|
typedef array __self;
|
2010-08-22 00:02:43 +00:00
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
2010-05-11 19:42:16 +00:00
|
|
|
typedef value_type* iterator;
|
|
|
|
typedef const value_type* const_iterator;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef const value_type* const_pointer;
|
2010-08-22 00:02:43 +00: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-11 19:42:16 +00:00
|
|
|
|
|
|
|
value_type __elems_[_Size > 0 ? _Size : 1];
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// No explicit construct/copy/destroy for aggregate type
|
2010-09-21 20:16:37 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u)
|
2011-06-30 21:18:19 +00:00
|
|
|
{_VSTD::fill_n(__elems_, _Size, __u);}
|
2011-05-31 21:06:33 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
|
2011-06-30 21:18:19 +00:00
|
|
|
{_VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// iterators:
|
2011-05-31 21:06:33 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator begin() _NOEXCEPT {return iterator(__elems_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);}
|
|
|
|
|
|
|
|
_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();}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// capacity:
|
2011-05-31 21:06:33 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
/*constexpr*/ size_type size() const _NOEXCEPT {return _Size;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
/*constexpr*/ size_type max_size() const _NOEXCEPT {return _Size;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool empty() const _NOEXCEPT {return _Size == 0;}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// element access:
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __elems_[__n];}
|
2010-08-22 00:02:43 +00:00
|
|
|
reference at(size_type __n);
|
|
|
|
const_reference at(size_type __n) const;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY reference front() {return __elems_[0];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_reference front() const {return __elems_[0];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];}
|
|
|
|
|
2011-05-31 21:06:33 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
value_type* data() _NOEXCEPT {return __elems_;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const value_type* data() const _NOEXCEPT {return __elems_;}
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
typename array<_Tp, _Size>::reference
|
|
|
|
array<_Tp, _Size>::at(size_type __n)
|
|
|
|
{
|
|
|
|
if (__n >= _Size)
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
throw out_of_range("array::at");
|
|
|
|
#else
|
|
|
|
assert(!"array::at out_of_range");
|
|
|
|
#endif
|
|
|
|
return __elems_[__n];
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
typename array<_Tp, _Size>::const_reference
|
|
|
|
array<_Tp, _Size>::at(size_type __n) const
|
|
|
|
{
|
|
|
|
if (__n >= _Size)
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
throw out_of_range("array::at");
|
|
|
|
#else
|
|
|
|
assert(!"array::at out_of_range");
|
|
|
|
#endif
|
|
|
|
return __elems_[__n];
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
bool
|
|
|
|
operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _Tp, size_t _Size>
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
2011-06-01 19:59:32 +00:00
|
|
|
typename enable_if
|
|
|
|
<
|
|
|
|
__is_swappable<_Tp>::value,
|
|
|
|
void
|
|
|
|
>::type
|
2010-05-11 19:42:16 +00:00
|
|
|
swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
2011-05-31 21:06:33 +00:00
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, size_t _Size>
|
2010-09-21 20:16:37 +00:00
|
|
|
class _LIBCPP_VISIBLE tuple_size<array<_Tp, _Size> >
|
|
|
|
: public integral_constant<size_t, _Size> {};
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, size_t _Size>
|
2010-09-21 20:16:37 +00:00
|
|
|
class _LIBCPP_VISIBLE tuple_size<const array<_Tp, _Size> >
|
|
|
|
: public integral_constant<size_t, _Size> {};
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2010-09-21 20:16:37 +00:00
|
|
|
class _LIBCPP_VISIBLE tuple_element<_Ip, array<_Tp, _Size> >
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef _Tp type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
2010-09-21 20:16:37 +00:00
|
|
|
class _LIBCPP_VISIBLE tuple_element<_Ip, const array<_Tp, _Size> >
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const _Tp type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
_Tp&
|
2011-05-31 21:06:33 +00:00
|
|
|
get(array<_Tp, _Size>& __a) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return __a[_Ip];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
const _Tp&
|
2011-05-31 21:06:33 +00:00
|
|
|
get(const array<_Tp, _Size>& __a) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return __a[_Ip];
|
|
|
|
}
|
|
|
|
|
2010-11-17 19:52:17 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
|
|
|
template <size_t _Ip, class _Tp, size_t _Size>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY inline
|
|
|
|
_Tp&&
|
2011-05-31 21:06:33 +00:00
|
|
|
get(array<_Tp, _Size>&& __a) _NOEXCEPT
|
2010-11-17 19:52:17 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return _VSTD::move(__a[_Ip]);
|
2010-11-17 19:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_ARRAY
|