5 #ifndef COTILA_VECTOR_VECTOR_H_ 6 #define COTILA_VECTOR_VECTOR_H_ 9 #include <cotila/detail/tmp.h> 10 #include <cotila/detail/assert.h> 12 #include <type_traits> 25 template <
typename T, std::
size_t N>
struct vector {
26 static_assert(N != 0,
"vector must contain at least one element");
27 COTILA_DETAIL_ASSERT_ARITHMETIC(T)
30 using size_type = std::size_t;
31 static constexpr size_type
size = N;
41 constexpr T &
operator[](size_type i) noexcept {
return array[i]; }
44 constexpr
const T &
operator[](size_type i)
const noexcept {
return array[i]; }
54 constexpr T *
begin() noexcept {
return array; }
61 constexpr T *
end() noexcept {
return array + N; }
64 constexpr
const T *
cbegin() const noexcept {
return array; }
67 constexpr
const T *
cend() const noexcept {
return array + N; }
100 template <
typename T,
typename... U>
102 ->vector<std::enable_if_t<(std::is_same_v<T, U> && ...), T>,
113 template <
typename T, std::
size_t N>
vector(
const T (&)[N])->vector<T, N>;
123 template <
typename T, std::
size_t N>
vector(
const T (&)[N][2])->vector<std::complex<T>, N>;
131 #endif // COTILA_VECTOR_VECTOR_H_ constexpr T * begin() noexcept
returns an iterator to the beginning
Definition: vector.h:54
constexpr const T * cbegin() const noexcept
returns an iterator to the beginning
Definition: vector.h:64
vector(T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization
A container representing a vector.
Definition: vector.h:25
decltype(auto) constexpr make_vector(Args... args)
constructs a cotila::vector from arguments
Definition: vector.h:85
constexpr T * end() noexcept
returns an iterator to the end
Definition: vector.h:61
decltype(auto) constexpr cotila::make_vector(Args... args)
constructs a cotila::vector from arguments
Definition: vector.h:85
constexpr const T & operator[](size_type i) const noexcept
access specified element
Definition: vector.h:44
static constexpr size_type size
size of the vector
Definition: vector.h:31
constexpr const T * cend() const noexcept
returns an iterator to the end
Definition: vector.h:67
constexpr T & operator[](size_type i) noexcept
access specified element
Definition: vector.h:41