13 #include <type_traits> 16 #include "atlas/library/config.h" 17 #include "atlas/parallel/omp/copy.h" 18 #include "atlas/parallel/omp/fill.h" 19 #include "atlas/runtime/Exception.h" 28 using const_iterator = T
const*;
33 template <typename size_t, typename std::enable_if<std::is_integral<size_t>::value,
int>::type = 0>
34 vector(
size_t size ) {
38 template <typename size_t, typename std::enable_if<std::is_integral<size_t>::value,
int>::type = 0>
39 vector(
size_t size,
const value_type& value ) : vector( size ) {
40 assign( size, value );
43 vector(
const vector& other ) { assign( other.data_, other.data_ + other.size_ ); }
45 vector( vector&& other ) {
46 std::swap( data_, other.data_ );
47 std::swap( size_, other.size_ );
48 std::swap( capacity_, other.capacity_ );
51 vector& operator=( vector other ) {
52 std::swap( data_, other.data_ );
53 std::swap( size_, other.size_ );
54 std::swap( capacity_, other.capacity_ );
58 template <
typename T2>
59 vector(
const std::initializer_list<T2>& list ) {
60 assign( list.begin(), list.end() );
69 template <typename idx_t, typename std::enable_if<std::is_integral<idx_t>::value,
int>::type = 0>
70 T& at(
idx_t i ) noexcept(
false ) {
72 throw_OutOfRange(
"atlas::vector", i, size_ );
77 template <typename idx_t, typename std::enable_if<std::is_integral<idx_t>::value,
int>::type = 0>
78 T
const& at(
idx_t i )
const noexcept(
false ) {
80 throw_OutOfRange(
"atlas::vector", i, size_ );
85 template <typename idx_t, typename std::enable_if<std::is_integral<idx_t>::value,
int>::type = 0>
86 T& operator[](
idx_t i ) {
87 #if ATLAS_VECTOR_BOUNDS_CHECKING 94 template <typename idx_t, typename std::enable_if<std::is_integral<idx_t>::value,
int>::type = 0>
95 T
const& operator[](
idx_t i )
const {
96 #if ATLAS_VECTOR_BOUNDS_CHECKING 103 const T* data()
const {
return data_; }
105 T* data() {
return data_; }
107 idx_t size()
const {
return size_; }
109 template <typename Size, typename std::enable_if<std::is_integral<Size>::value,
int>::type = 0>
110 void assign( Size n,
const value_type& value ) {
112 omp::fill( begin(), begin() + n, value );
115 template <typename Iter, typename std::enable_if<!std::is_integral<Iter>::value,
int>::type = 0>
116 void assign(
const Iter& first,
const Iter& last ) {
117 size_t size = std::distance( first, last );
119 omp::copy( first, last, begin() );
122 template <typename Size, typename std::enable_if<std::is_integral<Size>::value,
int>::type = 0>
123 void reserve( Size size ) {
124 if ( capacity_ != 0 )
125 ATLAS_NOTIMPLEMENTED;
129 template <typename size_t, typename std::enable_if<std::is_integral<size_t>::value,
int>::type = 0>
130 void resize(
size_t size ) {
131 if ( static_cast<idx_t>( size ) > 0 ) {
132 if ( capacity_ == 0 ) {
135 if ( static_cast<idx_t>( size ) > capacity_ ) {
136 ATLAS_NOTIMPLEMENTED;
141 const_iterator begin()
const {
return data_; }
142 const_iterator end()
const {
return data_ + size_; }
143 iterator begin() {
return data_; }
144 iterator end() {
return data_ + size_; }
145 const_iterator cbegin()
const {
return data_; }
146 const_iterator cend()
const {
return data_ + size_; }
149 value_type* data_{
nullptr};
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42