header_utils
Loading...
Searching...
No Matches
span.h
1
4
5#pragma once
6
7#if defined(__cpp_lib_span)
8#include <span>
9namespace ghassanpl
10{
11 using std::span;
12}
13#elif __has_include(<gsl/span>)
14#include <gsl/span>
15namespace ghassanpl
16{
17 using gsl::span;
18}
19#elif __has_include(<gsl/gsl-lite.hpp>)
20#include <gsl/gsl-lite.hpp>
21namespace ghassanpl
22{
23 using std20::span;
24}
25#elif defined(GHPL_SPAN_HEADER)
26#include GHPL_SPAN_HEADER
27#else
28#error "No span implementation found"
29#endif
30
31namespace ghassanpl
32{
33 namespace xf {
34 template <typename T> [[nodiscard]] constexpr auto as_span() noexcept { return [](auto const& val) { return ghassanpl::span{ val }; }; }
35 }
36
37 template <typename T>
38 [[nodiscard]] span<T> consume_n(span<T>& s, size_t n)
39 {
40 auto result = s.subspan(0, n);
41 s = s.subspan(n);
42 return result;
43 }
44
45 template <typename T>
46 [[nodiscard]] decltype(auto) consume(span<T>& s)
47 {
48 if constexpr (std::is_const_v<T>) {
49 auto const& ref = s[0];
50 s = s.subspan(1);
51 return ref;
52 }
53 else {
54 auto val = std::move(s[0]);
55 s = s.subspan(1);
56 return val;
57 }
58 }
59}
Contains functions that return functors which transform and return their inputs somehow; appropriate ...
Definition functional.h:254
Primary namespace for everything in this library.
Definition align+rec2.h:10