File: span.h

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (71 lines) | stat: -rw-r--r-- 2,204 bytes parent folder | download | duplicates (10)
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
70
71
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/span.h"

#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) && __cplusplus > 201703L
#      define OPENTELEMETRY_HAVE_SPAN
#    endif
#  endif
#  if !defined(OPENTELEMETRY_HAVE_SPAN)
#    // Check for Visual Studio span
#    if defined(_MSVC_LANG) && _HAS_CXX20
#      define OPENTELEMETRY_HAVE_SPAN
#    endif
#    // Check for other compiler span implementation
#    if !defined(_MSVC_LANG) && __has_include(<span>) && __cplusplus > 201703L
// This works as long as compiler standard is set to C++20
#      define OPENTELEMETRY_HAVE_SPAN
#    endif
#  endif
#  if !__has_include(<gsl/gsl>)
#    undef HAVE_GSL
#  endif
#endif

#if !defined(OPENTELEMETRY_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 OPENTELEMETRY_HAVE_SPAN
#  else
// No `gsl::span`, no `std::span`, fallback to `nostd::span`
#  endif

#else  // OPENTELEMETRY_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  // if OPENTELEMETRY_HAVE_SPAN