244 #ifndef _GSLP_dyn_array 245 #define _GSLP_dyn_array 333 #include <initializer_list> 345 typedef _Tp value_type;
346 typedef value_type& reference;
347 typedef const value_type& const_reference;
348 typedef value_type* iterator;
349 typedef const value_type* const_iterator;
350 typedef value_type* pointer;
351 typedef const value_type* const_pointer;
352 typedef size_t size_type;
353 typedef ptrdiff_t difference_type;
354 typedef std::reverse_iterator<iterator> reverse_iterator;
355 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
359 value_type * __base_;
360 dyn_array () noexcept : __size_(0), __base_(
nullptr) {}
362 static inline value_type* __allocate (
size_t count )
364 if (std::numeric_limits<size_t>::max() /
sizeof (value_type) <= count )
366 throw std::out_of_range(
"out_of_range");
368 return static_cast<value_type *
> (::operator
new(
sizeof(value_type) * count));
371 static inline void __deallocate ( value_type* __ptr ) noexcept
373 ::operator
delete(
static_cast<void *
> (__ptr));
379 dyn_array(size_type __c,
const value_type& __v);
381 dyn_array(std::initializer_list<value_type>);
386 inline iterator begin() noexcept {
return iterator(data()); }
387 inline const_iterator begin()
const noexcept {
return const_iterator(data()); }
388 inline const_iterator cbegin()
const noexcept {
return const_iterator(data()); }
389 inline iterator end() noexcept {
return iterator(data() + __size_); }
390 inline const_iterator end()
const noexcept {
return const_iterator(data() + __size_); }
391 inline const_iterator cend()
const noexcept {
return const_iterator(data() + __size_); }
393 inline reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
394 inline const_reverse_iterator rbegin()
const noexcept {
return const_reverse_iterator(end()); }
395 inline const_reverse_iterator crbegin()
const noexcept {
return const_reverse_iterator(end()); }
396 inline reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
397 inline const_reverse_iterator rend()
const noexcept {
return const_reverse_iterator(begin()); }
398 inline const_reverse_iterator crend()
const noexcept {
return const_reverse_iterator(begin()); }
401 inline size_type size()
const noexcept {
return __size_; }
402 inline size_type max_size()
const noexcept {
return __size_; }
403 inline bool empty()
const noexcept {
return __size_ == 0; }
406 inline reference operator[](size_type __n) {
return data()[__n]; }
407 inline const_reference operator[](size_type __n)
const {
return data()[__n]; }
409 inline reference front() {
return data()[0]; }
410 inline const_reference front()
const {
return data()[0]; }
411 inline reference back() {
return data()[__size_-1]; }
412 inline const_reference back()
const {
return data()[__size_-1]; }
414 inline const_reference at(size_type __n)
const;
415 inline reference at(size_type __n);
418 inline _Tp* data() noexcept {
return __base_; }
419 inline const _Tp* data()
const noexcept {
return __base_; }
422 inline void fill(
const value_type& __v) { std::fill_n(begin(), __size_, __v); }
429 __base_ = __allocate (__c);
430 value_type *__data = data ();
431 for ( __size_ = 0; __size_ < __c; ++__size_, ++__data )
432 ::
new (__data) value_type;
439 __base_ = __allocate (__c);
440 value_type *__data = data ();
441 for ( __size_ = 0; __size_ < __c; ++__size_, ++__data )
442 ::
new (__data) value_type (__v);
449 size_t sz = __il.size();
450 __base_ = __allocate (sz);
451 value_type *__data = data ();
452 auto src = __il.begin();
453 for ( __size_ = 0; __size_ < sz; ++__size_, ++__data, ++src )
454 ::
new (__data) value_type (*src);
461 size_t sz = __d.size();
462 __base_ = __allocate (sz);
463 value_type *__data = data ();
464 auto src = __d.begin();
465 for ( __size_ = 0; __size_ < sz; ++__size_, ++__data, ++src )
466 ::
new (__data) value_type (*src);
473 value_type *__data = data () + __size_;
474 for (
size_t i = 0; i < __size_; ++i )
475 (--__data)->_Tp::~_Tp();
476 __deallocate ( __base_ );
481 typename dyn_array<_Tp>::reference
486 throw std::out_of_range(
"dyn_array::at");
493 typename dyn_array<_Tp>::const_reference
498 throw std::out_of_range(
"dyn_array::at");
505 #endif // _GSLP_dyn_array Definition: dyn_array.h:340
Definition: dyn_array.h:337