akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
vector_traits.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include <cstddef>
9#include <utility>
10
12
13namespace linalg {
14
16template <typename T, std::size_t Dim>
17struct Vector;
18
27template <class Vec>
29
33template <typename T, std::size_t Dim>
36 using element_type = T;
38 static constexpr std::size_t dim = Dim;
39
41 template <typename... Ts>
42 static constexpr auto operator()(Ts&&... xs) {
43 static_assert(sizeof...(xs) == Dim,
44 "vector_traits::operator() requires exactly Dim coordinates");
46 std::size_t i = 0;
47 auto set_element = [&](const T& x) { vector(i++) = x; };
48 ((void)set_element(std::forward<Ts>(xs)), ...);
49 return vector;
50 }
51
53 static constexpr auto fill(const T& x) {
55 for (std::size_t i = 0; i < Dim; ++i) vector(i) = x;
56 return vector;
57 }
58};
59
61template <class Vec>
63
65template <class Vec>
67
69template <class Vec>
70inline constexpr std::size_t vector_dim_v = vector_traits_t<Vec>::dim;
71
79template <class T>
83
85template <typename T, std::size_t Dim>
87
89template <class Vec>
91
92} // namespace linalg
constexpr std::size_t vector_dim_v
Registered compile-time vector dimension.
std::remove_cvref_t< T > remove_cvref_t
Remove top-level const, volatile, and reference qualification.
typename vector_traits_t< Vec >::element_type vector_element_t
Registered vector coordinate type.
typename vector_scalar< remove_cvref_t< Vec > >::type vector_scalar_t
Fully unwrapped scalar type underlying a possibly nested vector.
Vector(T, Ts...) -> Vector< std::common_type_t< T, Ts... >, 1+sizeof...(Ts)>
Deduce coordinate type and dimension from constructor arguments.
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
Owning, fixed-size vector container.
Definition vector.hpp:36
Recursively obtain the non-vector scalar underlying a type.
remove_cvref_t< T > type
static constexpr auto operator()(Ts &&... xs)
Construct from exactly Dim coordinates in index order.
static constexpr auto fill(const T &x)
Construct a vector whose coordinates are all equal to x.
Customization point for fixed-size vector metadata.