ipfs-chromium
Loading...
Searching...
No Matches
span.h
1#ifndef IPFS_SPAN_H_
2#define IPFS_SPAN_H_
3
4#if __cpp_lib_span
5#include <span>
6
7namespace ipfs {
8template <class Value>
9using span = std::span<Value>;
10} // namespace ipfs
11
12#elif __has_include("base/containers/span.h")
13
14#include "base/containers/span.h"
15namespace ipfs {
16template <class Value>
17using span = base::span<Value>;
18} // namespace ipfs
19
20#elif __has_include(<absl/types/span.h>)
21
22#include <absl/types/span.h>
23namespace ipfs {
24template <class Value>
25using span = absl::Span<Value>;
26} // namespace ipfs
27
28#elif __has_include(<boost/core/span.hpp>)
29
30#include <boost/core/span.hpp>
31namespace ipfs {
32template <class Value>
33using span = boost::span<Value>;
34} // namespace ipfs
35
36#elif __has_include(<boost/beast/core/span.hpp>)
37
38// Prior to Boost 1.78, span did not exist in core yet
39#include <boost/beast/core/span.hpp>
40#include <vector>
41namespace ipfs {
42template <class Value>
43class span : public boost::beast::span<Value> {
44 public:
45 span(Value* d, std::size_t n) : boost::beast::span<Value>{d, n} {}
46
47 template <class V2>
48 span(std::vector<V2> const& v)
49 : boost::beast::span<Value>{v.data(), v.size()} {}
50
51 span subspan(std::size_t off) const {
52 return span{this->data() + off, this->size() - off};
53 }
54 Value& operator[](std::size_t i) { return this->data()[i]; }
55};
56} // namespace ipfs
57
58#else
59
60#error \
61 "No good implementation of span available. Implement one, move to a newer C++, or provide Boost or Abseil."
62
63#endif
64
65#endif // IPFS_SPAN_H_