小编Flo*_*oop的帖子

模板模板参数和默认值

请考虑以下代码:

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++ template-templates variadic-templates c++11 c++17

11
推荐指数
1
解决办法
804
查看次数

在C++ Range-v3库中解压缩

是否可以使用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)

sorting c++11 boost-range range-v3

4
推荐指数
1
解决办法
1264
查看次数