summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/tr1/array
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-22 05:32:16 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-22 05:32:16 +0000
commitfd8431c84811e14566423cbc55645074300ec2fa (patch)
tree1c19eaec8b161244a85ea6ebe24ea14c66a07346 /libstdc++-v3/include/tr1/array
parentdfaec4a91ea4562335a383795530f62a31b9d629 (diff)
downloadppe42-gcc-fd8431c84811e14566423cbc55645074300ec2fa.tar.gz
ppe42-gcc-fd8431c84811e14566423cbc55645074300ec2fa.zip
2004-10-21 Benjamin Kosnik <bkoz@redhat.com>
* include/tr1/array (array): Make safe for zero-sized arrays. (array::end): Return one past the end. (array::at): Use __throw_out_of_range, include functexcept.h. (operator==): Implement. (operator!=): Same. (operator<): Same. (operator>): Same. (operator>=): Same. (operator<=): Same. * testsuite/tr1/6_containers/array/capacity/(empty.cc, max_size.cc, size.cc): New. * testsuite/tr1/6_containers/array/comparison_operators/(equal.cc, greater.cc, greater_or_equal.cc, less.cc, less_or_equal.cc, not_equal): New. * testsuite/tr1/6_containers/array/cons/aggregate_initialization.cc: New. * testsuite/tr1/6_containers/array/element_access/at_out_of_range.cc: New. * testsuite/tr1/6_containers/array/iterators/end_is_one_past.cc: New. * testsuite/tr1/6_containers/array/requirements/(contiguous.cc, instantiate, typedefs, zero_size_arrays): New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89429 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/tr1/array')
-rw-r--r--libstdc++-v3/include/tr1/array48
1 files changed, 25 insertions, 23 deletions
diff --git a/libstdc++-v3/include/tr1/array b/libstdc++-v3/include/tr1/array
index 7f092ad4852..d355285f56e 100644
--- a/libstdc++-v3/include/tr1/array
+++ b/libstdc++-v3/include/tr1/array
@@ -32,6 +32,8 @@
#include <new>
#include <iterator>
+#include <algorithm>
+#include <bits/functexcept.h>
//namespace std::tr1
namespace std
@@ -40,12 +42,9 @@ namespace tr1
{
// [6.2.2] Class template array template
// Requires complete type _Tp.
- // Use of char array allows _Tp to skirt default constructable requirement.
template<typename _Tp, size_t _Nm = 1>
struct array
{
- enum { _S_index = _Nm };
-
typedef _Tp value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
@@ -56,7 +55,11 @@ namespace tr1
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- value_type _M_instance[_Nm];
+ // Compile time constant without other dependencies.
+ enum { _S_index = _Nm };
+
+ // Support for zero-sized arrays mandatory.
+ value_type _M_instance[_Nm ? _Nm : 1];
// No explicit construct/copy/destroy for aggregate type.
@@ -77,11 +80,11 @@ namespace tr1
iterator
end()
- { return reinterpret_cast<iterator>(&_M_instance[_S_index - 1]); }
+ { return reinterpret_cast<iterator>(&_M_instance[_Nm]); }
const_iterator
end() const
- { return reinterpret_cast<const_iterator>(&_M_instance[_S_index - 1]); }
+ { return reinterpret_cast<const_iterator>(&_M_instance[_Nm]); }
reverse_iterator
rbegin()
@@ -101,17 +104,13 @@ namespace tr1
// Capacity.
size_type
- size() const { return _S_index; }
+ size() const { return _Nm; }
size_type
- max_size() const
- {
- // XXX Not specified. Unnecessary, this is fixed-size.
- return _S_index;
- }
+ max_size() const { return _Nm; }
bool
- empty() const;
+ empty() const { return size() == 0; }
// Element access.
reference
@@ -125,16 +124,16 @@ namespace tr1
const_reference
at(size_type __n) const
{
- if (__builtin_expect(__n > _S_index, false))
- throw std::bad_alloc();
+ if (__builtin_expect(__n > _Nm, false))
+ std::__throw_out_of_range("array::at");
return reinterpret_cast<const_reference>(_M_instance[__n]);
}
reference
at(size_type __n)
{
- if (__builtin_expect(__n > _S_index, false))
- throw std::bad_alloc();
+ if (__builtin_expect(__n > _Nm, false))
+ std::__throw_out_of_range("array::at");
return reinterpret_cast<reference>(_M_instance[__n]);
}
@@ -161,7 +160,7 @@ namespace tr1
template<typename _Tp, size_t _Nm>
bool
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return false; }
+ { return std::equal(__one.begin(), __one.end(), __two.begin()); }
template<typename _Tp, size_t _Nm>
bool
@@ -170,23 +169,26 @@ namespace tr1
template<typename _Tp, size_t _Nm>
bool
- operator<(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return false; }
+ operator<(const array<_Tp, _Nm>& a, const array<_Tp, _Nm>& b)
+ {
+ return std::lexicographical_compare(a.begin(), a.end(),
+ b.begin(), b.end());
+ }
template<typename _Tp, size_t _Nm>
bool
operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return false; }
+ { return __two < __one; }
template<typename _Tp, size_t _Nm>
bool
operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return false; }
+ { return !(__one > __two); }
template<typename _Tp, size_t _Nm>
bool
operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
- { return false; }
+ { return !(__one < __two); }
// [6.2.2.2] Specialized algorithms.
template<typename _Tp, size_t _Nm>
OpenPOWER on IntegriCloud