简体   繁体   English

麻烦用st编译std :: tuple

[英]trouble compiling std::tuple with clang

I have trouble compiling templates with clang.. Any help appreciated. 我在用clang编译模板时遇到了麻烦。任何帮助。

Although the author of the library claims he compiled below code with gcc on linux, when I try to compile using clang, it complains about compiling templates below: 尽管该库的作者声称他在Linux上使用gcc在下面的代码下进行了编译,但是当我尝试使用clang进行编译时,它却抱怨编译以下模板:

// this gives the error of "expected expression" //这会产生“预期表达式”错误

template<class T1, class T2, class T3> static ostream& operator << (
    ostream& out, const std::tuple<T1, T2, T3>& t) {
  out << t.get<0>() << " " << t.get<1>() << " " << t.get<2>();
  return out;
}

this gives the error: 这给出了错误:

no member named 'get' in 'std::__1::tuple<std::__1::basic_string<char>, std::__1::basic_string<char>, int, int>'

Code: 码:

void save_by_conns(vector<real_t> &container, const string &nam)
{
    LOOP(const WC_CONN_PAIR &p, connections)
    {
        VDI begin = container.begin() + p.second.get<2>();
        VDI end = container.begin() + p.second.get<3>();
        if (begin != end)
        {
            save_range(make_pair(begin, end), p.second.get<1>() + "_" + nam);
        }
    }
}

为了检索tuple元素,应使用非成员std::get函数:

out << ::std::get<0>(t) << " " << ::std::get<1>(t) << " " << ::std::get<2>(t);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带引用的 std::tuple 在 clang 中编译失败,但在 gcc 中编译失败 - std::tuple with reference fails to compile in clang, but not in gcc 在&#39;std :: hash上的Clang编译错误 <unsigned long> “ - Clang compiling error on 'std::hash<unsigned long>' Apple 的 clang 不能将 &lt;=&gt; 与 std::tuple 一起使用 - Apple's clang can't use <=> with std::tuple 使用 Apple Clang 14.0 编译时,std::ranges::any_of 失败 - std::ranges::any_of fails when compiling with Apple Clang 14.0 Clang 错误“未定义模板 std::tuple_size 的隐式实例化<auto> ”</auto> - Clang error “implicit instantiation of undefined template std::tuple_size<auto>” std :: atomic的来历 <double> 用clang编译时未实现? - How come std::atomic<double> isn't implemented when compiling with clang? 为什么将影响 lambda 的代码编译为 std::function 如此缓慢,尤其是使用 Clang? - Why is compiling a code affecting lambda to std::function so slow, in particular with Clang? g ++ 5中std :: unordered_set的类型不完整的编译错误,在clang ++中编译 - incomplete type for std::unordered_set compiling error in g++5, compiles in clang++ 用clang编译MSVC std lib。 在类范围内显式模板函数专门化 - Compiling MSVC std lib with clang. Explicit template function specialization at class scope 用 clang 和 gfortran 编译 - Compiling with clang and gfortran
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM