grpc
src
core
lib
gprpp
src/core/lib/gprpp/match.h
Go to the documentation of this file.
1
// Copyright 2021 gRPC authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef GRPC_CORE_LIB_GPRPP_MATCH_H
16
#define GRPC_CORE_LIB_GPRPP_MATCH_H
17
18
#include <
grpc/support/port_platform.h
>
19
20
#include <type_traits>
21
22
#include "absl/types/variant.h"
23
24
#include "
src/core/lib/gprpp/overload.h
"
25
26
namespace
grpc_core
{
27
28
namespace
detail
{
29
30
template
<
typename
... Cases>
31
struct
MatchPointerExtractor
{
32
OverloadType
<Cases...>
cases
;
33
template
<
typename
T>
34
auto
operator()
(
T
&
value
) -> decltype(
cases
(&
value
)) {
35
return
cases
(&
value
);
36
}
37
};
38
39
}
// namespace detail
40
50
template
<
typename
... Fs,
typename
T0,
typename
... Ts>
51
auto
Match
(
const
absl::variant<T0, Ts...>
&
value
, Fs... fs)
52
-> decltype(std::declval<
OverloadType<Fs...>
>()(std::declval<T0>())) {
53
return
absl::visit
(
Overload
(
std::move
(fs)...),
value
);
54
}
55
65
template
<
typename
... Fs,
typename
T0,
typename
... Ts>
66
auto
MatchMutable
(
absl::variant<T0, Ts...>
*
value
, Fs... fs)
67
-> decltype(std::declval<
OverloadType<Fs...>
>()(std::declval<T0*>())) {
68
return
absl::visit
(
detail::MatchPointerExtractor<Fs...>
{
OverloadType
<Fs...>(
69
std::move
(fs)...)},
70
*
value
);
71
}
72
73
}
// namespace grpc_core
74
75
#endif // GRPC_CORE_LIB_GPRPP_MATCH_H
grpc_core
Definition:
call_metric_recorder.h:31
detail
Definition:
test_winkernel.cpp:39
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_core::Overload
OverloadType< Cases... > Overload(Cases... cases)
Definition:
overload.h:53
overload.h
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition:
abseil-cpp/absl/utility/utility.h:221
grpc_core::detail::MatchPointerExtractor::cases
OverloadType< Cases... > cases
Definition:
src/core/lib/gprpp/match.h:32
value
const char * value
Definition:
hpack_parser_table.cc:165
grpc_core::detail::MatchPointerExtractor
Definition:
src/core/lib/gprpp/match.h:31
grpc_core::Match
auto Match(const absl::variant< T0, Ts... > &value, Fs... fs) -> decltype(std::declval< OverloadType< Fs... >>()(std::declval< T0 >()))
Definition:
src/core/lib/gprpp/match.h:51
grpc_core::OverloadType
Definition:
overload.h:25
grpc_core::detail::MatchPointerExtractor::operator()
auto operator()(T &value) -> decltype(cases(&value))
Definition:
src/core/lib/gprpp/match.h:34
absl::visit
variant_internal::VisitResult< Visitor, Variants... > visit(Visitor &&vis, Variants &&... vars)
Definition:
abseil-cpp/absl/types/variant.h:430
absl::variant
Definition:
abseil-cpp/absl/types/internal/variant.h:46
grpc_core::MatchMutable
auto MatchMutable(absl::variant< T0, Ts... > *value, Fs... fs) -> decltype(std::declval< OverloadType< Fs... >>()(std::declval< T0 * >()))
Definition:
src/core/lib/gprpp/match.h:66
port_platform.h
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:22