msl 1.3.0
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// Copyright 2023-2025 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _da006854_5a52_4f29_8aa1_24be101f8935
5#define _da006854_5a52_4f29_8aa1_24be101f8935
6
7#include <array>
8#include <initializer_list>
9#include <ostream>
10
11namespace msl
12{
13
15template<std::size_t N, typename T>
16class Vector
17{
18public:
20 using Container = std::array<T, N>;
21
23 using value_type = typename Container::value_type;
24
26 using const_iterator = typename Container::const_iterator;
28 using iterator = typename Container::iterator;
29
32
38 Vector(std::initializer_list<T> && initializer);
39 ~Vector() = default;
40 Vector(Vector<N, T> const &) = default;
41 Vector(Vector<N, T> &&) = default;
42 Vector<N, T> & operator=(Vector<N, T> const &) = default;
44
46 bool operator==(Vector<N, T> const & other) const;
47
49 bool operator!=(Vector<N, T> const & other) const;
50
52 constexpr std::size_t size() const { return N; }
53
55 T const & operator[](std::size_t i) const;
56
58 T & operator[](std::size_t i);
59
62
65
68
71
74
77
79 Vector<N, T> const & operator+() const;
80
83
85 T norm() const;
86
89
92
95
98
101
104
106 template<typename Dest>
108
109private:
110 Container _data;
111};
112
115
118
121
124
127
130
132template<std::size_t N, typename T>
134
136template<std::size_t N, typename T>
138
140template<std::size_t N, typename T>
142
144template<std::size_t N, typename T>
146
148template<std::size_t N, typename T>
150
152template<std::size_t N, typename T>
154
156template<std::size_t N, typename T>
158
160template<std::size_t N, typename T>
161std::ostream & operator<<(std::ostream & stream, Vector<N,T> const & v);
162
163}
164
165namespace std
166{
167
169template<std::size_t N, typename T>
171
172}
173
174#include "Vector.txx"
175
176#endif // _da006854_5a52_4f29_8aa1_24be101f8935
A vector of arithmetic types.
Definition Vector.h:17
Vector< N, T > & operator%=(T right)
In-place remainder of division by a scalar.
Vector(std::initializer_list< T > &&initializer)
Initialize the values to given sequence.
Vector()
Zero-initialize the values.
Vector< N, Dest > cast() const
Element-wise cast.
Vector< N, T > & operator=(Vector< N, T > const &)=default
const_iterator cbegin() const
Constant iterator to the first element.
std::array< T, N > Container
Underlying container.
Definition Vector.h:20
Vector< N, T > & operator%=(Vector< N, T > const &right)
Elementwise in-place remainder of division.
~Vector()=default
const_iterator cend() const
Constant iterator after the last element.
Vector< N, T > operator-() const
Opposite operator.
Vector(Vector< N, T > const &)=default
typename Container::iterator iterator
Iterator to values.
Definition Vector.h:28
Vector< N, T > & operator+=(Vector< N, T > const &right)
Element-wise in-place addition.
Vector< N, T > const & operator+() const
Identity operator.
bool operator==(Vector< N, T > const &other) const
Test equality of all elements.
iterator end()
Iterator after the last element.
const_iterator begin() const
Constant iterator to the first element.
Vector< N, T > & operator/=(T right)
In-place division by a scalar.
Vector(Vector< N, T > &&)=default
T & operator[](std::size_t i)
Access an element.
iterator begin()
Iterator to the first element.
typename Container::const_iterator const_iterator
Constant iterator to values.
Definition Vector.h:26
const_iterator end() const
Constant iterator after the last element.
Vector< N, T > & operator=(Vector< N, T > &&)=default
T norm() const
Euclidean norm (i.e. L2 norm)
Vector< N, T > & operator*=(T scalar)
In-place multiplication by a scalar.
Vector< N, T > & operator-=(Vector< N, T > const &right)
Element-wise in-place subtraction.
bool operator!=(Vector< N, T > const &other) const
Test difference of any element.
T const & operator[](std::size_t i) const
Access an element.
constexpr std::size_t size() const
Return the number of elements.
Definition Vector.h:52
typename Container::value_type value_type
Stored value.
Definition Vector.h:23
Top-level namespace of the msl library.
Definition acceleration.h:17
Vector< N, T > operator*(Vector< N, T > left, T right)
Multiplication by a scalar.
Vector< N, T > operator+(Vector< N, T > left, Vector< N, T > const &right)
Element-wise addition.
Vector< N, T > operator/(Vector< N, T > left, T right)
Division by a scalar.
std::ostream & operator<<(std::ostream &stream, Mask const &mask)
Visual representation of the mask.
Vector< N, T > operator%(Vector< N, T > left, Vector< N, T > const &right)
Element-wise remainder of division.
Vector< N, T > operator-(Vector< N, T > left, Vector< N, T > const &right)
Element-wise subtraction.
STL namespace.