OGLplus
(0.59.0)
a C++ wrapper for rendering APIs
eagine
vect
from.hpp
Go to the documentation of this file.
1
#ifndef EAGINE_VECT_FROM_HPP
9
#define EAGINE_VECT_FROM_HPP
10
11
#include "../assert.hpp"
12
#include "../maybe_unused.hpp"
13
#include "../types.hpp"
14
#include "
data.hpp
"
15
16
namespace
eagine::vect {
17
18
template
<
typename
T,
int
N,
bool
V>
19
struct
from_array {
20
static
auto
apply(
const
T* d,
span_size_t
n) noexcept -> data_t<T, N, V> {
21
EAGINE_ASSERT(N <=
int
(n));
22
EAGINE_MAYBE_UNUSED(n);
23
data_t<T, N, V> r;
24
for
(
int
i = 0; i < N; ++i) {
25
r[i] = d[i];
26
}
27
return
r;
28
}
29
};
30
31
#if EAGINE_VECT_OPTS
32
33
template
<
typename
T,
bool
V>
34
struct
from_array<T, 0, V> {
35
static
constexpr
auto
apply(
const
T*,
int
) noexcept {
36
return
data_t<T, 0, V>{};
37
}
38
};
39
40
template
<
typename
T,
bool
V>
41
struct
from_array<T, 1, V> {
42
static
auto
apply(
const
T* d,
span_size_t
n) noexcept {
43
EAGINE_ASSERT(1 <= n);
44
EAGINE_MAYBE_UNUSED(n);
45
return
data_t<T, 1, V>{d[0]};
46
}
47
};
48
49
template
<
typename
T,
bool
V>
50
struct
from_array<T, 2, V> {
51
static
auto
apply(
const
T* d,
span_size_t
n) noexcept {
52
EAGINE_ASSERT(2 <= n);
53
EAGINE_MAYBE_UNUSED(n);
54
return
data_t<T, 2, V>{d[0], d[1]};
55
}
56
};
57
58
template
<
typename
T,
bool
V>
59
struct
from_array<T, 3, V> {
60
static
auto
apply(
const
T* d,
span_size_t
n) noexcept {
61
EAGINE_ASSERT(3 <= n);
62
EAGINE_MAYBE_UNUSED(n);
63
return
data_t<T, 3, V>{d[0], d[1], d[2]};
64
}
65
};
66
67
template
<
typename
T,
bool
V>
68
struct
from_array<T, 4, V> {
69
static
auto
apply(
const
T* d,
span_size_t
n) noexcept {
70
EAGINE_ASSERT(4 <= n);
71
EAGINE_MAYBE_UNUSED(n);
72
return
data_t<T, 4, V>{d[0], d[1], d[2], d[3]};
73
}
74
};
75
76
template
<
typename
T,
bool
V>
77
struct
from_array<T, 8, V> {
78
static
auto
apply(
const
T* d,
span_size_t
n) noexcept {
79
EAGINE_ASSERT(8 <= n);
80
EAGINE_MAYBE_UNUSED(n);
81
return
data_t<T, 8, V>{d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]};
82
}
83
};
84
85
#endif
86
87
// from shorter array and fallback value
88
template
<
typename
T,
int
N,
bool
V>
89
struct
from_saafv {
90
static
auto
apply(
const
T* d,
span_size_t
n, T v) noexcept {
91
data_t<T, N, V> r = {};
92
for
(
int
i = 0; i < N && i < int(n); ++i) {
93
r[i] = d[i];
94
}
95
for
(
int
i =
int
(n); i < N; ++i) {
96
r[i] = v;
97
}
98
return
r;
99
}
100
};
101
102
}
// namespace eagine::vect
103
104
#endif // EAGINE_VECT_FROM_HPP
eagine::span_size_t
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition:
types.hpp:36
data.hpp
Copyright © 2015-2021
Matúš Chochlík
.
<
chochlik -at -gmail.com
>
Documentation generated on Tue Apr 13 2021 by
Doxygen
(version 1.8.17).