forked from boostorg/array
Changes in response to public review comments
[SVN r7690]
This commit is contained in:
@ -21,7 +21,10 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <boost/config.hpp> // for std::size_t and std::ptrdiff_t workarounds
|
// BUG-FIX for compilers that don't support
|
||||||
|
// std::size_t and std::ptrdiff_t yet
|
||||||
|
// (such as gcc)
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ namespace boost {
|
|||||||
const_iterator begin() const { return elems; }
|
const_iterator begin() const { return elems; }
|
||||||
iterator end() { return elems+N; }
|
iterator end() { return elems+N; }
|
||||||
const_iterator end() const { return elems+N; }
|
const_iterator end() const { return elems+N; }
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||||
@ -63,11 +66,6 @@ namespace boost {
|
|||||||
const_reference operator[](size_type i) const { return elems[i]; }
|
const_reference operator[](size_type i) const { return elems[i]; }
|
||||||
|
|
||||||
// at() with range check
|
// at() with range check
|
||||||
// note: rangecheck() is public because we have implemented array
|
|
||||||
// as aggregate, which forbids non-public members
|
|
||||||
void rangecheck (size_type i) const {
|
|
||||||
if (i >= size()) { throw std::range_error("array"); }
|
|
||||||
}
|
|
||||||
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
||||||
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
||||||
|
|
||||||
@ -83,8 +81,9 @@ namespace boost {
|
|||||||
static size_type max_size() { return N; }
|
static size_type max_size() { return N; }
|
||||||
enum { static_size = N };
|
enum { static_size = N };
|
||||||
|
|
||||||
|
public:
|
||||||
// swap (note: linear complexity)
|
// swap (note: linear complexity)
|
||||||
void swap (array& y) {
|
void swap (array<T,N>& y) {
|
||||||
std::swap_ranges(begin(),end(),y.begin());
|
std::swap_ranges(begin(),end(),y.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,10 +91,24 @@ namespace boost {
|
|||||||
const T* data() const { return elems; }
|
const T* data() const { return elems; }
|
||||||
|
|
||||||
// assignment with type conversion
|
// assignment with type conversion
|
||||||
//template <typename T2>
|
template <typename T2>
|
||||||
//T& operator= (const array<T2,N>& rhs) {
|
array<T,N>& operator= (const array<T2,N>& rhs) {
|
||||||
// std::copy (begin(),end(),rhs.begin());
|
std::copy(rhs.begin(),rhs.end(), begin());
|
||||||
//}
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign one value to all elements
|
||||||
|
void assign (const T& value)
|
||||||
|
{
|
||||||
|
std::fill_n(begin(),size(),value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// check range (may be private because it is static)
|
||||||
|
static void rangecheck (size_type i) {
|
||||||
|
if (i >= size()) { throw std::range_error("array"); }
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// comparisons
|
// comparisons
|
||||||
@ -126,7 +139,7 @@ namespace boost {
|
|||||||
|
|
||||||
// global swap()
|
// global swap()
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
inline void swap (const array<T,N>& x, const array<T,N>& y) {
|
inline void swap (array<T,N>& x, array<T,N>& y) {
|
||||||
x.swap(y);
|
x.swap(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user