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