[英]How to get a pointer to std::get<0,tuple<int,int>>)?
I know that std::get is overloaded. 我知道std :: get重载了。 And I know that to extract an overload I need to cast to a specific signature.
而且我知道要提取过载,我需要转换为特定的签名。 Let say I need a pointer to std::get which returns non-const ref to 1st element from std::tuple&.
假设我需要一个指向std :: get的指针,该指针将非常量ref从std :: tuple&返回到第一元素。 Below is one of my many attempts (does not compile):
以下是我的许多尝试之一(无法编译):
auto f = static_cast<
int& (*)(std::tuple<int,int>&) noexcept
>(
&std::get<(size_t)0u, std::tuple<int,int>>
);
How should I specify this static_cast? 我应该如何指定此static_cast?
The signature of the tuple get is (directly taken from libstdc++): 元组get的签名是(直接取自libstdc ++):
template<std::size_t __i, typename... _Elements>
constexpr typename __add_ref<
typename tuple_element<__i, tuple<_Elements...>>::type
>::type
get(tuple<_Elements...>& __t) noexcept
As such the template parameter to get is the different types of the tuple, not the tuple, so the function you take the address from should be: 由于要获取的模板参数是元组的不同类型,而不是元组,因此从中获取地址的函数应为:
&std::get<(size_t)0u,int,int>
Do you need a pointer to an actual std::get or any function with the same behavior will do? 您是否需要一个指向实际std :: get的指针,或者具有相同行为的任何函数都可以呢? If so you can just wrap it in a lambda:
如果是这样,您可以将其包装在lambda中:
auto f = [](std::tuple<int,int>& tuple) -> int&
{
return std::get<0>(tuple);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.