假设我有一个采用类对象的模板函数:
template<class T>
void Foo(T obj);
Run Code Online (Sandbox Code Playgroud)
和一个类定义如下:
class Bar
{
public:
Bar(int a, bool b): _a(a), _b(b) {}
private:
int _a;
bool _b;
};
Run Code Online (Sandbox Code Playgroud)
有没有办法让下面的代码编译?
Foo<Bar>(5,false);
Foo<Bar>({5,false}); // i know this works, just wondering if i can remove the brackets somehow.
Run Code Online (Sandbox Code Playgroud) 我有一个类模板,我想编写如下:
template </*what to put here?*/ T>
Class Bar {};
Run Code Online (Sandbox Code Playgroud)
我想强制 T 只能是作用域枚举中的值。我使用了此处is_scoped_enum提供的类型检查,但是我能想到的最好的办法就是更改为如下所示:Bar
template <typename T>
concept ScopeEnum = is_scoped_enum<T>::value;
template<ScopeEnum SE, SE se>
class Bar {};
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它并Bar保持预期的效果?