Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经开始使用Boost 概念检查库。但是,在阅读文档之后,我似乎没有找到一种方法来验证概念中的方法是否返回某种类型。但是,我也没有看到任何说这是不可能的,这很奇怪。
那么,如果返回类型不正确,是否可以编写一个会失败的概念?
double pi(){ return 3.1415; } int main(){ int int_pi{pi()}; }
使用{}要求转换初始化变量导致信息丢失时,这是编译错误。
{}
或者:
#include <type_traits> int main(){ static_assert(std::is_same<decltype(pi()), double>::value, "pi() must return double"); }
我认为第二个代码不需要任何评论。