【发布时间】:2016-11-30 11:59:30
【问题描述】:
不幸的是,我发现的关于concepts 的唯一教程是concept lite 教程(而且非常基础)。即使有技术规范,也有一些我不知道如何转化为概念的签名功能(可能只是因为我的英语不好,而且我不能很好地阅读技术规范)。
所以有一个签名函数列表我仍然不知道如何“翻译”:
CFoo --> 类 CFoo {};
void Foo1() const;CFoo& Foo2();void Foo3(CFoo&);{static, friend, ... } void Foo4();template < typename ... Args > void Foo5(Args && ... args);
我想为具有这些功能的类提供某种接口。 甚至不知道在这一点上是否可能。 Foo2 和 Foo3 好像是同一个问题。
老实说,我真的很想知道 Foo2 和 Foo5。
我为 Foo2 尝试了一些东西,但我对 Foo5 没有任何想法:
class Handle {};
template < typename Object >
concept bool C_Object =
requires(Handle handle) {
{get(handle)} -> Object&
};
template < C_Object Object >
class Foo {
Object obj;
};
int main() {
Foo<int> test;
return 0;
}
我知道这不会编译,因为 Foo 没有 get menber,但这些不是正确的错误:
Test1.cpp:6:16: error: there are no arguments to ‘get’ that depend on a template parameter, so a declaration of ‘get’ must be available [-fpermissive]
{get(handle)} -> Object&
^
Test1.cpp:6:16: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
Test1.cpp: In function ‘int main()’:
Test1.cpp:18:10: error: template constraint failure
Foo<int> test;
^
Test1.cpp:18:10: note: constraints not satisfied
Test1.cpp:4:14: note: within ‘template<class Object> concept const bool C_Object<Object> [with Object = int]’
concept bool C_Object =
^~~~~~~~
Test1.cpp:4:14: note: with ‘Handle handle’
Test1.cpp:4:14: note: the required expression ‘get(handle)’ would be ill-formed
如果有人可以指出一些资源,或者,为什么不,一个解决方案。会很棒的。
祝你有美好的一天
【问题讨论】:
标签: c++ templates variadic-templates c++-concepts