这个卷曲支架CPP语法是什么?
las,很难搜索诸如括号之类的符号。
我遇到了此代码:
#include <functional>
#include <iostream>
template <typename A, typename B, typename C = std::less<>>
bool fun(A a, B b, C cmp = C{})
{
return cmp(a, b);
}
int main()
{
std::cout
<< std::boolalpha
<< fun(1, 2) << ' ' // true
<< fun(1.0, 1) << ' ' // false
<< fun(1, 2.0) << ' ' // true
<< std::less<int>{}(5, 5.6) << ' ' // false: 5 < 5 (warn: implicit conversion)
<< std::less<double>{}(5, 5.6) << ' ' // true: 5.0 < 5.6
<< std::less<int>{}(5.6, 5.7) << ' ' // false: 5 < 5 (warn: implicit conversion)
<< std::less{}(5, 5.6) << ' ' // true: less<void>: 5.0 < 5.6
<< '\n';
}
在 https://en.cppreference.com/w /CPP/实用程序/功能/少。
语句中的牙套c {}
,std :: Less&lt&gt; {}(5,5.6)
是指的是什么?
Alas, it's hard to google for symbols like braces.
I came across this code:
#include <functional>
#include <iostream>
template <typename A, typename B, typename C = std::less<>>
bool fun(A a, B b, C cmp = C{})
{
return cmp(a, b);
}
int main()
{
std::cout
<< std::boolalpha
<< fun(1, 2) << ' ' // true
<< fun(1.0, 1) << ' ' // false
<< fun(1, 2.0) << ' ' // true
<< std::less<int>{}(5, 5.6) << ' ' // false: 5 < 5 (warn: implicit conversion)
<< std::less<double>{}(5, 5.6) << ' ' // true: 5.0 < 5.6
<< std::less<int>{}(5.6, 5.7) << ' ' // false: 5 < 5 (warn: implicit conversion)
<< std::less{}(5, 5.6) << ' ' // true: less<void>: 5.0 < 5.6
<< '\n';
}
in https://en.cppreference.com/w/cpp/utility/functional/less.
What do braces in the statements C{}
, std::less<int>{}(5, 5.6)
mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它创建一个实例
std :: selly&lt&lt; int&lt; /code>
然后通过
5,5.6
作为bool Operator()(const int&amp;,const int&amp;)
的参数大致相同
it create an instance of
std::less<int>
then pass
5,5.6
as the parameter to it'sbool operator()(const int&, const int&)
it's roughly the same as