msl 1.3.0
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// Copyright 2023-2026 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
41 template<typename T2>
42 Vector(T2 x);
43
45 template<typename T2, typename T3>
46 Vector(T2 const & x, T3 const & y);
47
49 template<typename T2, typename T3, typename T4>
50 Vector(T2 const & x, T3 const & y, T4 const & z);
51
52 ~Vector() = default;
53 Vector(Vector<N, T> const &) = default;
54 Vector(Vector<N, T> &&) = default;
55 Vector<N, T> & operator=(Vector<N, T> const &) = default;
56 Vector<N, T> & operator=(Vector<N, T> &&) = default;
57
59 bool operator==(Vector<N, T> const & other) const;
60
62 bool operator!=(Vector<N, T> const & other) const;
63
65 constexpr std::size_t size() const { return N; }
66
68 T const & operator[](std::size_t i) const;
69
71 T & operator[](std::size_t i);
72
75
78
81
84
87
90
92 Vector<N, T> const & operator+() const;
93
96
98 T norm() const;
99
102
105
108
111
114
117
119 template<typename Dest>
121
122private:
123 Container _data;
124};
125
128
131
134
137
140
143
145template<std::size_t N, typename T>
147
149template<std::size_t N, typename T>
151
153template<std::size_t N, typename T>
155
157template<std::size_t N, typename T>
159
161template<std::size_t N, typename T>
163
165template<std::size_t N, typename T>
167
169template<std::size_t N, typename T>
171
173template<std::size_t N, typename T>
174std::ostream & operator<<(std::ostream & stream, Vector<N,T> const & v);
175
176}
177
178namespace std
179{
180
182template<std::size_t N, typename T>
184
185}
186
187#include "Vector.txx"
188
189#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(T2 const &x, T3 const &y, T4 const &z)
Initialize the values from three scalars.
Vector< N, Dest > cast() const
Element-wise cast.
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.
const_iterator cend() const
Constant iterator after the last element.
Vector< N, T > operator-() const
Opposite operator.
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.
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(T2 const &x, T3 const &y)
Initialize the values from two scalars.
T norm() const
Euclidean norm (i.e. L2 norm).
Vector< N, T > & operator*=(T scalar)
In-place multiplication by a scalar.
Vector(T2 x)
Initialize the values from one 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:65
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.
Vector< 2, long > Vector2l
2D vector of longs
Definition Vector.h:130
Vector< 3, double > Vector3d
3D vector of doubles
Definition Vector.h:136
Vector< 3, long > Vector3l
3D vector of longs
Definition Vector.h:139
Vector< 2, bool > Vector2b
2D vector of booleans
Definition Vector.h:133
Vector< 3, bool > Vector3b
3D vector of booleans
Definition Vector.h:142
Vector< N, T > operator%(Vector< N, T > left, Vector< N, T > const &right)
Element-wise remainder of division.
Vector< 2, double > Vector2d
2D vector of doubles
Definition Vector.h:127
std::ostream & operator<<(std::ostream &stream, iPATMask const &mask)
Visual representation of the mask.
Vector< N, T > operator-(Vector< N, T > left, Vector< N, T > const &right)
Element-wise subtraction.
STL namespace.
msl::Vector< N, T > abs(msl::Vector< N, T > v)
Element-wise absolute value.