diff --git a/include/boost/array.hpp b/include/boost/array.hpp index f957a7d..eb32cb7 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -21,7 +21,10 @@ #include #include -#include // 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 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 reverse_iterator; typedef std::reverse_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& 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 - //T& operator= (const array& rhs) { - // std::copy (begin(),end(),rhs.begin()); - //} + template + array& operator= (const array& 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 - inline void swap (const array& x, const array& y) { + inline void swap (array& x, array& y) { x.swap(y); }