元组和可变参数模板的编译问题
Compile issue with tuples and variadic templates
我遇到了一个看似复杂的问题。
我正在尝试为 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
我的问题是,这种方法有效吗? 我不知道为什么它一定是错误的,或者编译器想从我这里得到什么。
但除此之外,如果我缺少更简单的方法,我会很高兴听到它。
我猜问题是*Tp
不是decltype
的有效表达式。
也许试试declval
?
std::tuple<decltype(*std::declval<Tp>())...>
或迭代器特征:
std::tuple<typename std::iterator_traits<Tp>::value_type...>
typename std::tuple<decltype(*Tp)...>>::type
这根本没有意义,因为:
Tp
是一个类型参数,所以*Tp
没有任何意义。std::tuple
没有任何嵌套::type
。所以std::tuple<whatever>::type
没有意义。
根据您的评论,我想您需要std::iterator_traits
为:
std::tuple<typename std::iterator_traits<Tp>::value_type...>
希望有帮助。
相关文章:
- Rextester 语言编译C++问题
- C++ 多级虚拟继承编译问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- Qt Visual Studio 2015 加载项编译问题
- libssh 问题编译问题未定义的错误
- 在 armhf 上使用 cmake 在 qt 上的编译问题 "Syntax error: wird unexpected (expecting " ) " "
- LLVM 万花筒教程 JIT 编译问题
- PX 转换例程编译问题
- 模板类编译问题与 typedef 变量
- 在 Ubuntu 16.04 LTS 上使用 c++ 编译问题?
- 编译问题与 Ubuntu Linux
- C++编译问题错误 - C2332:<类:缺少标记名称>
- AIX C++映射编译问题
- Ubuntu 下的 Cmake 和 Intel IPP 的编译问题
- 如何解决我在 Ubuntu 19.04 下使用 GLFW 时遇到的这个编译问题?
- wxWebView在Ubuntu上的编译问题
- C++constexpr编译问题
- CMake - OpenVR 编译问题
- C++ SD 总线源文件编译问题