【发布时间】:2020-07-12 00:09:08
【问题描述】:
我正在使用 C++17,并且我有 std::tuple 的 const &T 类型。例如:
template <typename... members>
auto make_cr_tuple(members const &...args) -> decltype(auto) {
return std::make_tuple(std::cref(args)...);
}
int main() {
std::string s;
int i = 0;
auto crt = make_cr_tuple(s, i); // std::tuple<const std::string &, const int &>
}
我想要一种方法来声明每个值类型的元组,删除 const 和引用限定符。例如,可能是这样的:
using decayed = decayed_tuple<decltype(crt)>::type
我想我可能会使用这样的东西,但这还不够。
template <typename T>
struct decayed_tuple {
using type = decltype(std::apply(std::make_tuple, T{}));
};
显然这不起作用,因为make_tuple 是一个未解析的重载函数。
我确实需要std::make_tuple<???>,但我不知道如何将T 中的类型获取到模板包中。请注意,我假设 T 在这里是默认可构造的。
【问题讨论】: