fixed_vector / fixed-size sequence container
This library adds as part of its IndependentFeatures a complement to std::vector
in the form of cxxomfort::fixed_vector
, a vector-like container whose size is specified at construction and remains invariant through the lifetime of the object - the oft sought holy grail of a "vector without resize".
- Header:
cxxomfort/library.hpp
. - Transparent (C++-style) header: to be implemented
- Namespace:
cxxomfort::
A fixed_vector<T>
behaves much like a std::vector<T>
, and shares much of the interface, except the size of the container is set-up as a constant at the time of construction, and as such the resize, insert, erase, capacity or reserve members are not available.
Here follows a brief of the interface:
template <typename T> class fixed_vector { public: typedef T value_type; typedef T const* const_pointer; typedef _implementation_defined difference_type; typedef _implementation_defined const_iterator; fixed_vector () = deleted; fixed_vector (fixed_vector const&); fixed_vector (size_t count, T const& value); // [ value, value, value, ...] count times fixed_vector (std::initializer_list<T> const&); // C++11 onward template <typename Iterator> fixed_vector (Iterator begin, Iterator end); fixed_vector (fixed_vector&&); // operator= as in std::vector // begin and end accesors as in std::vector, based off the following: const_iterator begin() const noexcept; iterator begin() noexcept; _implementation_defined front () const; _implementation_defined back () const; const_pointer data () const noexcept; difference_type size () const noexcept; size_type max_size () const noexcept; // returns size() bool empty () const noexcept; // only false for zero-element fixed_vector _implementation_defined at (size_t) const; _implementation_defined at (size_t); T const& operator[] (size_t) const noexcept; T& operator[] (size_t) noexcept; void fill (T const&); };
- Storage for fixed_vector is guaranteed to be contiguous.
- fixed_vector does not support allocators at the time of this writing (Apr 2017).
- fixed_vector is copyable and movable, even in C++03 mode.
operator=
can change the size because it is assigning a copy of a completely different object.
- Back to IndependentFeatures.
- Compare: Extras/array_ref, Extras/dynarray.