【发布时间】:2015-11-20 18:22:15
【问题描述】:
您好,我想实现元组。 让我知道这出了什么问题以及如何正确实施它。我想从一个函数返回三个值,其中第一个值是整数,最后一个值是数组。
template <typename T1, typename T2, typename T3>
struct t_untuple
{
T1& a1;
T2& a2;
T3& a3;
explicit t_untuple(T1& a1, T2& a2, T3& a3) : a1(a1), a2(a2), a3(a3) { }
t_untuple<T1, T2, T3>& operator = (const tuple <T1, T2, T3>& p)
{
a1 = p.first;
a2 = p.second;
a3 = p.third;
return *this;
}
};
// Our functor helper (creates it)
template <typename T1, typename T2, typename T3>
t_untuple<T1, T2, T3> unpair(T1& a1, T2& a2, T3& a3)
{
return t_unpair<T1, T2, T3>(a1, a2, a3);
}
帮我解决这个问题。
我在 const tuple & p 处得到 无法解析符号“元组”,因此 p.third 也是一个错误
【问题讨论】:
-
当你尝试使用它时会发生什么?
-
为什么不创建一个包含 int,int,std::array
的类(假设 T 变化) -
你能帮忙看看怎么做吗?我不确定我现在可以如何进行。
-
你有什么理由不使用
std::tuple?