SDL3pp
A slim C++ wrapper for SDL3
Toggle main menu visibility
Loading...
Searching...
No Matches
SDL3pp
SDL3pp_spanRef.h
1
#ifndef SDL3PP_SPAN_REF_H_
2
#define SDL3PP_SPAN_REF_H_
3
4
#include <concepts>
5
#include <ranges>
6
#include <span>
7
8
namespace
SDL
{
9
10
template
<
class
T,
class
BASE>
11
concept
DerivedWrapper
=
12
std::derived_from<T, BASE> &&
sizeof
(T) ==
sizeof
(BASE);
13
22
template
<
class
T>
23
class
SpanRef
24
{
25
std::span<T> value;
26
27
public
:
28
constexpr
SpanRef() =
default
;
29
31
template
<DerivedWrapper<T> U,
size_t
N>
32
constexpr
SpanRef
(U (&other)[N])
33
: value(static_cast<T*>(other), N)
34
{
35
}
36
38
template
<DerivedWrapper<T> U>
39
constexpr
SpanRef
(
const
std::span<U>& other)
40
: value(other.
data
(), other.
size
())
41
{
42
}
43
45
template
<std::contiguous_iterator It>
46
requires
DerivedWrapper<std::iter_value_t<It>
, T>
47
constexpr
SpanRef
(It first,
size_t
count)
48
: value((T*)(&*first), count)
49
{
50
}
51
53
template
<std::contiguous_iterator It, std::sized_sentinel_for<It> End>
54
requires
DerivedWrapper<std::iter_value_t<It>
, T>
55
constexpr
SpanRef
(It first, End last)
56
: value((T*)(&*first), size_t(last - first))
57
{
58
}
59
61
template
<std::ranges::contiguous_range R>
62
requires
DerivedWrapper<std::iter_value_t<std::ranges::iterator_t<R>
>, T>
63
constexpr
SpanRef
(R&& range)
64
: SpanRef(std::begin(range), std::end(range))
65
{
66
}
67
69
constexpr
size_t
size
()
const
{
return
value.size(); }
70
72
constexpr
size_t
size_bytes
()
const
{
return
value.size_bytes(); }
73
75
constexpr
T*
data
()
const
{
return
value.data(); }
76
};
77
78
}
// namespace SDL
79
80
#endif
/* SDL3PP_SPAN_REF_H_ */
SDL::SpanRef::SpanRef
constexpr SpanRef(It first, End last)
Constructor.
Definition
SDL3pp_spanRef.h:55
SDL::SpanRef::SpanRef
constexpr SpanRef(U(&other)[N])
Constructor.
Definition
SDL3pp_spanRef.h:32
SDL::SpanRef::data
constexpr T * data() const
Retrieves contained data.
Definition
SDL3pp_spanRef.h:75
SDL::SpanRef::SpanRef
constexpr SpanRef(It first, size_t count)
Constructor.
Definition
SDL3pp_spanRef.h:47
SDL::SpanRef::SpanRef
constexpr SpanRef(const std::span< U > &other)
Constructor.
Definition
SDL3pp_spanRef.h:39
SDL::SpanRef::SpanRef
constexpr SpanRef(R &&range)
Constructor.
Definition
SDL3pp_spanRef.h:63
SDL::SpanRef::size
constexpr size_t size() const
Retrieves contained size.
Definition
SDL3pp_spanRef.h:69
SDL::SpanRef::size_bytes
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition
SDL3pp_spanRef.h:72
SDL::DerivedWrapper
Definition
SDL3pp_spanRef.h:11
SDL
Main include header for the SDL3pp library.
Generated by
1.17.0