-
Notifications
You must be signed in to change notification settings - Fork 423
/
span.h
69 lines (63 loc) · 1.93 KB
/
span.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/version.h"
// Standard library implementation requires at least C++17 compiler.
// Older C++14 compilers may provide support for __has_include as a
// conforming extension.
#if defined __has_include
# if __has_include(<version>) // Check for __cpp_{feature}
# include <version>
# if defined(__cpp_lib_span)
# define HAVE_SPAN
# endif
# endif
# if !defined(HAVE_SPAN)
# // Check for Visual Studio span
# if defined(_MSVC_LANG) && _HAS_CXX20
# define HAVE_SPAN
# endif
# // Check for other compiler span implementation
# if !defined(_MSVC_LANG) && __has_include(<span>)
// This works as long as compiler standard is set to C++20
# define HAVE_SPAN
# endif
# endif
# if !__has_include(<gsl/gsl>)
# undef HAVE_GSL
# endif
#endif
#if !defined(HAVE_SPAN)
# if defined(HAVE_GSL)
# include <type_traits>
// Guidelines Support Library provides an implementation of std::span
# include <gsl/gsl>
OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{
using gsl::dynamic_extent;
template <class ElementType, std::size_t Extent = gsl::dynamic_extent>
using span = gsl::span<ElementType, Extent>;
} // namespace nostd
OPENTELEMETRY_END_NAMESPACE
# define HAVE_SPAN
# else
// No `gsl::span`, no `std::span`, fallback to `nostd::span`
# endif
#else // HAVE_SPAN
// Using std::span (https://wg21.link/P0122R7) from Standard Library available in C++20 :
// - GCC libstdc++ 10+
// - Clang libc++ 7
// - MSVC Standard Library 19.26*
// - Apple Clang 10.0.0*
# include <limits>
# include <span>
OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{
constexpr std::size_t dynamic_extent = (std::numeric_limits<std::size_t>::max());
template <class ElementType, std::size_t Extent = nostd::dynamic_extent>
using span = std::span<ElementType, Extent>;
} // namespace nostd
OPENTELEMETRY_END_NAMESPACE
#endif // of HAVE_SPAN