【发布时间】:2013-01-26 19:31:47
【问题描述】:
我遇到了一个看似复杂的问题。
我正在尝试为 zip 函数创建一个迭代器类(试图模仿 python 的生成器 zip 函数)。
我的整个班级都在http://ideone.com/c7rm40
template<size_t I = 0, typename... Tp>
inline typename std::enable_if<(I == sizeof...(Tp)), typename std::tuple<decltype(*Tp)...>>::type
constructImpl(std::tuple<Tp...> const& its) {
core/StarAlgorithm.hpp|550 col 3| error: expected ‘(’ before ‘constructImpl’
core/StarAlgorithm.hpp|550 col 3| error: expected ‘>’ before ‘constructImpl’
core/StarAlgorithm.hpp|550 col 45| error: template argument 2 is invalid
core/StarAlgorithm.hpp|550 col 47| error: expected ‘::’ before ‘{’ token
core/StarAlgorithm.hpp|550 col 47| error: expected identifier before ‘{’ token
core/StarAlgorithm.hpp|550 col 47| error: expected unqualified-id before ‘{’ token
我的问题是,这种方法是否有效?我不知道为什么它一定是错误的,或者编译器想从我这里得到什么。
但除此之外,如果我缺少更简单的方法,我会很高兴听到它。
【问题讨论】:
-
typename std::tuple<decltype(*Tp)...>不应该有typename。不知道这是否是问题。 -
为什么
decltype(*Tp)中有*?你为什么要使用decltype开头?Tp是本身就是一个类型。 -
我把它添加进来作为尝试的东西,我已经中途破解了一段时间,只是为了排除一些事情。它也不适用于删除
typename。 -
@Nawaz,因为这个函数接受一个不同类型的迭代器的元组,解引用它们,并返回一个解引用类型的元组。
-
@OmnipotentEntity:
decltype不适用于 type。和*Tp甚至没有意义!Tp不是指针值,是类型!
标签: c++ tuples variadic-templates template-meta-programming decltype