请考虑以下代码:
template<typename T>
struct A { };
// same as A, but with one extra defaulted parameter
template<typename T, typename F = int>
struct B { };
template<template<typename> typename T>
T<int> build() { return {}; }
int main()
{
build<A>(); // works in gcc and clang
build<B>(); // works in gcc, does not work in clang
}
Run Code Online (Sandbox Code Playgroud)
g ++(7.3.0)编译代码就好了,但是,clang ++(5.0.1)会发出以下命令:
example.cpp:14:5: error: no matching function for call to 'build'
build<B>(); // works in gcc, does not work in clang
^~~~~~~~ …Run Code Online (Sandbox Code Playgroud) 是否可以使用C++ Range-v3库解压缩先前压缩的向量?我希望它的行为类似于Haskell的解压缩函数或Python的zip(*list).
例如,当按照另一个向量的值对向量进行排序时,这将是方便的:
using namespace ranges;
std::vector<std::string> names {"john", "bob", "alice"};
std::vector<int> ages {32, 19, 35};
// zip names and ages
auto zipped = view::zip(names, ages);
// sort the zip by age
sort(zipped, [](auto &&a, auto &&b) {
return std::get<1>(a) < std::get<1>(b);
});
// put the sorted names back into the original vector
std::tie(names, std::ignore) = unzip(zipped);
Run Code Online (Sandbox Code Playgroud)