Loading...
Searching...
No Matches
static_vector
// vi:set ft=cpp: -*- Mode: C++ -*-
#pragma once
#include "type_traits"
namespace cxx {
template<typename T, typename IDX = unsigned>
class static_vector
{
private:
template<typename X, typename IDX2> friend class static_vector;
T *_v;
IDX _l;
public:
typedef T value_type;
typedef IDX index_type;
static_vector() = default;
static_vector(value_type *v, index_type length) : _v(v), _l(length) {}
template<typename Z,
typename = enable_if_t<is_same<remove_extent_t<Z>, T>::value>>
constexpr static_vector(Z &v) : _v(v), _l(array_size(v))
{}
template<typename X,
typename = enable_if_t<is_convertible<X, T>::value>>
static_vector(static_vector<X, IDX> const &o) : _v(o._v), _l(o._l) {}
index_type size() const { return _l; }
bool empty() const { return _l == 0; }
value_type &operator [] (index_type idx) { return _v[idx]; }
value_type const &operator [] (index_type idx) const { return _v[idx]; }
value_type *begin() { return _v; }
value_type *end() { return _v + _l; }
value_type const *begin() const { return _v; }
value_type const *end() const { return _v + _l; }
value_type const *cbegin() const { return _v; }
value_type const *cend() const { return _v + _l; }
index_type index(value_type const *o) const { return o - _v; }
index_type index(value_type const &o) const { return &o - _v; }
};
}
cxx::static_vector::index
index_type index(value_type const *o) const
Get the index of the given element of the array.
Definition static_vector:54
cxx::static_vector::static_vector
static_vector(static_vector< X, IDX > const &o)
Conversion from compatible arrays.
Definition static_vector:38
cxx
Our C++ library.
Definition arith:11