File: variant.h

package info (click to toggle)
opentelemetry-cpp 1.23.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,368 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 38; python: 31
file content (85 lines) | stat: -rw-r--r-- 2,483 bytes parent folder | download | duplicates (5)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/version.h"

#if defined(OPENTELEMETRY_STL_VERSION)
#  if OPENTELEMETRY_STL_VERSION >= 2017
#    include "opentelemetry/std/variant.h"
#    define OPENTELEMETRY_HAVE_STD_VARIANT
#  endif
#endif

#if !defined(OPENTELEMETRY_HAVE_STD_VARIANT)

// We use a LOCAL snapshot of Abseil that is known to compile with Visual Studio 2015.
// Header-only. Without compiling the actual Abseil binary. As Abseil moves on to new
// toolchains, it may drop support for Visual Studio 2015 in future versions.

#  if defined(__EXCEPTIONS)
#    include <exception>
OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{

class bad_variant_access : public std::exception
{
public:
  virtual const char *what() const noexcept override { return "bad_variant_access"; }
};

[[noreturn]] inline void throw_bad_variant_access()
{
  throw bad_variant_access{};
}
}  // namespace nostd
OPENTELEMETRY_END_NAMESPACE
#    define THROW_BAD_VARIANT_ACCESS opentelemetry::nostd::throw_bad_variant_access()
#  else
#    define THROW_BAD_VARIANT_ACCESS std::terminate()
#  endif

#  ifdef _MSC_VER
// Abseil variant implementation contains some benign non-impacting warnings
// that should be suppressed if compiling with Visual Studio 2017 and above.
#    pragma warning(push)
#    pragma warning(disable : 4245)  // conversion from int to const unsigned _int64
#    pragma warning(disable : 4127)  // conditional expression is constant
#  endif

#  include "opentelemetry/nostd/internal/absl/base/options.h"

namespace absl
{
namespace OTABSL_OPTION_NAMESPACE_NAME
{
template <class T>
struct variant_size;
template <typename... Ts>
class variant;
}  // namespace OTABSL_OPTION_NAMESPACE_NAME
}  // namespace absl

#  include "opentelemetry/nostd/internal/absl/types/variant.h"

#  ifdef _MSC_VER
#    pragma warning(pop)
#  endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{
using absl::OTABSL_OPTION_NAMESPACE_NAME::get;
using absl::OTABSL_OPTION_NAMESPACE_NAME::get_if;
using absl::OTABSL_OPTION_NAMESPACE_NAME::holds_alternative;
using absl::OTABSL_OPTION_NAMESPACE_NAME::monostate;
using absl::OTABSL_OPTION_NAMESPACE_NAME::variant;
using absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t;
using absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size;
using absl::OTABSL_OPTION_NAMESPACE_NAME::visit;
}  // namespace nostd
OPENTELEMETRY_END_NAMESPACE

#endif /* OPENTELEMETRY_HAVE_STD_VARIANT */