Go to the documentation of this file.
9 #ifndef EAGINE_SPAN_HPP
10 #define EAGINE_SPAN_HPP
29 template <
typename T,
typename P,
typename S,
typename Output>
34 for(
const auto& e : s) {
49 template <
typename Input,
typename T,
typename P,
typename S>
53 reinterpret_cast<char*
>(s.data()), limit_cast<std::streamsize>(s.size()));
61 template <
typename Output,
typename T,
typename P,
typename S>
65 reinterpret_cast<const char*
>(s.data()),
66 limit_cast<std::streamsize>(s.size()));
73 template <
typename T,
typename P,
typename S>
76 enable_if_t<!std::is_same_v<std::remove_const_t<T>,
char>, std::ostream&> {
77 return list_to_stream(out, s);
84 template <
typename T,
typename P,
typename S>
87 enable_if_t<std::is_same_v<std::remove_const_t<T>,
char>, std::ostream&> {
88 return write_to_stream(out,
absolute(s));
98 template <
typename T,
typename P,
typename S>
103 return {spn[i++],
true};
109 template <
typename Src>
110 static inline auto make_span_getter(
span_size_t& i,
const Src& src) {
111 return make_span_getter(i,
view(src));
122 template <
typename T,
typename P,
typename S,
typename Transform>
126 Transform transform) {
127 return [&i, spn, transform]() -> decltype(transform(std::declval<T>())) {
129 return transform(spn[i++]);
135 template <
typename Src,
typename Transform>
137 make_span_getter(
span_size_t& i,
const Src& src, Transform transform) {
138 return make_span_getter(i,
view(src), std::move(transform));
147 template <
typename T,
typename P,
typename S>
150 return [&i, spn](
auto value)
mutable ->
bool {
152 spn[i++] = T(std::move(value));
159 template <
typename Dst>
160 static inline auto make_span_putter(
span_size_t& o, Dst& dst) {
161 return make_span_putter(o,
cover(dst));
171 template <
typename T,
typename P,
typename S,
typename Transform>
175 Transform transform) {
176 return [&i, spn, transform](
auto value)
mutable ->
bool {
178 if(
auto transformed = transform(value)) {
179 spn[i++] = T(std::move(
extract(transformed)));
187 template <
typename Dst,
typename Transform>
189 make_span_putter(
span_size_t& o, Dst& dst, Transform transform) {
190 return make_span_putter(o,
cover(dst), std::move(transform));
195 #endif // EAGINE_SPAN_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
static auto make_span_putter(span_size_t &i, memory::basic_span< T, P, S > spn, Transform transform)
Makes a callable setting consecutive elements of a span starting at i.
Definition: span.hpp:172
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
static auto make_span_getter(span_size_t &i, memory::basic_span< T, P, S > spn)
Makes a callable that returns consecutive span elements starting at i.
Definition: span.hpp:100
static auto make_span_getter(span_size_t &i, memory::basic_span< T, P, S > spn, Transform transform)
Makes a callable getting consecutive, transformed span elements starting at i.
Definition: span.hpp:123
Primary template for conditionally valid values.
Definition: decl.hpp:49
static auto write_to_stream(Output &out, memory::basic_span< T, P, S > s) -> auto &
Helper function for raw-reading spans into output streams.
Definition: span.hpp:62
basic_span< T, T *, S > span
Default alias for basic memory spans with native pointer type.
Definition: span.hpp:415
static constexpr auto cover_one(T *pointer) noexcept -> span_if_mutable< T >
Creates a single-element mutable span from the specified pointer.
Definition: span.hpp:451
static constexpr auto view_one(const T *pointer) noexcept -> const_span< T >
Creates a single-const-element view from the specified pointer.
Definition: span.hpp:444
static constexpr auto view(const C &container) noexcept
Creates a const view over a compatible contiguous container.
Definition: span.hpp:513
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
static auto operator<<(std::ostream &out, memory::basic_span< T, P, S > s) -> std::enable_if_t<!std::is_same_v< std::remove_const_t< T >, char >, std::ostream & >
Operator for printing generic element spans into output streams.
Definition: span.hpp:74
static auto read_from_stream(Input &in, memory::basic_span< T, P, S > s) -> auto &
Helper function for raw-reading spans from output streams.
Definition: span.hpp:50
static auto operator<<(std::ostream &out, memory::basic_span< T, P, S > s) -> std::enable_if_t< std::is_same_v< std::remove_const_t< T >, char >, std::ostream & >
Operator for printing spans of string characters into output streams.
Definition: span.hpp:85
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the span.
Definition: span.hpp:246
static constexpr auto cover(C &container) noexcept
Creates a mutable span covering a compatible contiguous container.
Definition: span.hpp:523
static auto list_to_stream(Output &out, memory::basic_span< T, P, S > s) -> Output &
Helper function for pretty-printing spans as lists into output streams.
Definition: span.hpp:30
static auto make_span_putter(span_size_t &i, memory::basic_span< T, P, S > spn)
Makes a callable setting consecutive elements of a span starting at i.
Definition: span.hpp:149
static constexpr auto absolute(basic_span< T, P, S > spn) noexcept -> basic_span< T, T *, S >
Converts argument to span using a native pointer type.
Definition: span.hpp:407