VCCC  2024.05
VisualCamp Common C++ library
holds_alternative.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2/4/24.
3 //
4 
5 #ifndef VCCC_VARIANTS_HOLDS_ALTERNATIVE_HPP
6 #define VCCC_VARIANTS_HOLDS_ALTERNATIVE_HPP
7 
8 #include <type_traits>
9 
12 
13 namespace vccc {
14 namespace detail {
15 
16 template<typename T>
17 struct variant_holds_alternative_visitor {
18  template<typename U, std::size_t I>
19  constexpr bool operator()(const U&, in_place_index_t<I>) const {
21  }
22 };
23 
24 } // namespace detail
25 
28 
29 template<typename T, typename... Types, std::enable_if_t<
30  (type_sequence<Types...>::template count<T> == 1)
31 , int> = 0>
32 constexpr bool holds_alternative(const variant<Types...>& v) noexcept {
33  return detail::variant_raw_visit(v.index(), v._base().union_, detail::variant_holds_alternative_visitor<T>{});
34 }
35 
37 
38 } // namespace vccc
39 
40 #endif // VCCC_VARIANTS_HOLDS_ALTERNATIVE_HPP
a type-safe discriminated union
Definition: variant.hpp:589
constexpr std::size_t index() const noexcept
Definition: variant.hpp:662
constexpr VCCC_INLINE_OR_STATIC std::size_t variant_npos
Definition: variant_npos.hpp:17
constexpr bool holds_alternative(const variant< Types... > &v) noexcept
Definition: holds_alternative.hpp:32
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35