简体   繁体   中英

trouble compiling std::tuple with clang

I have trouble compiling templates with clang.. Any help appreciated.

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:

// 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM