SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
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
8namespace SDL {
9
10template<class T, class BASE>
12 std::derived_from<T, BASE> && sizeof(T) == sizeof(BASE);
13
22template<class T>
24{
25 std::span<T> value;
26
27public:
28 constexpr SpanRef() = default;
29
30 template<DerivedWrapper<T> U, size_t N>
31 constexpr SpanRef(U (&other)[N])
32 : value(static_cast<T*>(other), N)
33 {
34 }
35
36 template<DerivedWrapper<T> U>
37 constexpr SpanRef(const std::span<U>& other)
38 : value(other.data(), other.size())
39 {
40 }
41
42 template<std::contiguous_iterator It>
44 constexpr SpanRef(It first, size_t count)
45 : value((T*)(&*first), count)
46 {
47 }
48
49 template<std::contiguous_iterator It, std::sized_sentinel_for<It> End>
51 constexpr SpanRef(It first, End last)
52 : value((T*)(&*first), size_t(last - first))
53 {
54 }
55 template<std::ranges::contiguous_range R>
57 constexpr SpanRef(R&& range)
58 : SpanRef(std::begin(range), std::end(range))
59 {
60 }
61
62 constexpr size_t size() const { return value.size(); }
63
64 constexpr T* data() const { return value.data(); }
65};
66
67} // namespace SDL
68
69#endif /* SDL3PP_SPAN_REF_H_ */
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
Definition SDL3pp_spanRef.h:11
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7