小编Ric*_*nes的帖子

“template<class... Ts> 结构重载 : Ts... { using Ts::operator()...; };” 是什么意思?意思是,它如何与 std::visit 一起使用?

此代码片段取自https://en.cppreference.com/w/cpp/utility/variant/visit

using var_t = std::variant<int, long, double, std::string>;
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
std::vector<var_t> vec = {10, 15l, 1.5, "hello"};

for (auto& v: vec) {
// 4. another type-matching visitor: a class with 3 overloaded operator()'s
// Note: The `(auto arg)` template operator() will bind to `int` and `long`
//       in this case, but in its absence the `(double arg)` operator()
//       *will also* bind to `int` and `long` because both are implicitly
// …
Run Code Online (Sandbox Code Playgroud)

c++ templates std

2
推荐指数
1
解决办法
872
查看次数

标签 统计

c++ ×1

std ×1

templates ×1