相关疑难解决方法(0)

模板模板参数和默认值

请考虑以下代码:

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
查看次数