variant_alternative.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include <type_traits>
  5. #include "opentelemetry/nostd/detail/type_pack_element.h"
  6. #include "opentelemetry/nostd/detail/variant_fwd.h"
  7. #include "opentelemetry/version.h"
  8. OPENTELEMETRY_BEGIN_NAMESPACE
  9. namespace nostd
  10. {
  11. template <std::size_t I, typename T>
  12. struct variant_alternative;
  13. template <std::size_t I, typename T>
  14. using variant_alternative_t = typename variant_alternative<I, T>::type;
  15. template <std::size_t I, typename T>
  16. struct variant_alternative<I, const T> : std::add_const<variant_alternative_t<I, T>>
  17. {};
  18. template <std::size_t I, typename T>
  19. struct variant_alternative<I, volatile T> : std::add_volatile<variant_alternative_t<I, T>>
  20. {};
  21. template <std::size_t I, typename T>
  22. struct variant_alternative<I, const volatile T> : std::add_cv<variant_alternative_t<I, T>>
  23. {};
  24. template <std::size_t I, typename... Ts>
  25. struct variant_alternative<I, variant<Ts...>>
  26. {
  27. static_assert(I < sizeof...(Ts), "index out of bounds in `std::variant_alternative<>`");
  28. using type = detail::type_pack_element_t<I, Ts...>;
  29. };
  30. } // namespace nostd
  31. OPENTELEMETRY_END_NAMESPACE