为什么参数相关的查找对 std::make_tuple 不起作用?

问题描述 投票:0回答:1

tie
而不是
std::tie
在这里可以工作,因为依赖于参数的查找:

std::tuple<int, std::string> tup = std::make_tuple<int, std::string>(1, "a");
int i;
std::string str;
tie(i, str) = tup;

但是为什么

make_tuple
需要
std::

c++ namespaces argument-dependent-lookup
1个回答
1
投票

为了使 ADL 正常工作,您需要

std
命名空间中的参数之一。

在对

tie
的调用中就是这种情况(
str
std::string
),但在对
make_tuple
的调用中则不然(相邻的 1 和“a”都是)。

您可以通过提供

std::string
来使用 ADL,如下所示:

//-----------------------------------------------------------------vvvvvvvvvvv--------
std::tuple<int, std::string> tup = make_tuple<int, std::string>(1, std::string{ "a" });
© www.soinside.com 2019 - 2024. All rights reserved.