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 <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 {
|
||||
|
||||
@ -45,7 +48,7 @@ namespace boost {
|
||||
const_iterator begin() const { return elems; }
|
||||
iterator end() { return elems+N; }
|
||||
const_iterator end() const { return elems+N; }
|
||||
|
||||
|
||||
// reverse iterator support
|
||||
typedef std::reverse_iterator<iterator> 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]; }
|
||||
|
||||
// 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]; }
|
||||
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; }
|
||||
enum { static_size = N };
|
||||
|
||||
public:
|
||||
// swap (note: linear complexity)
|
||||
void swap (array& y) {
|
||||
void swap (array<T,N>& y) {
|
||||
std::swap_ranges(begin(),end(),y.begin());
|
||||
}
|
||||
|
||||
@ -92,10 +91,24 @@ namespace boost {
|
||||
const T* data() const { return elems; }
|
||||
|
||||
// assignment with type conversion
|
||||
//template <typename T2>
|
||||
//T& operator= (const array<T2,N>& rhs) {
|
||||
// std::copy (begin(),end(),rhs.begin());
|
||||
//}
|
||||
template <typename T2>
|
||||
array<T,N>& operator= (const array<T2,N>& rhs) {
|
||||
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
|
||||
@ -126,7 +139,7 @@ namespace boost {
|
||||
|
||||
// global swap()
|
||||
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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user