C++11中none_of的用法求助
答案:2 悬赏:40 手机版
解决时间 2021-03-03 09:49
- 提问者网友:饥饿走向夜
- 2021-03-02 11:42
C++11中none_of的用法求助
最佳答案
- 五星知识达人网友:动情书生
- 2021-03-02 12:49
实现是属于标准模板库的一部分,但是很可惜。gcc在windows下的实现中对ctype文件进行了修改,mingw的ctype文件中的isupper被mingw重载(虽然我没找到是在哪里,但是gcc这么认为的)。
所以gcc需要对isupper进行写莫名奇妙的处理:用其他函数包装之后再传递,或者使用强制类型转换。
typedef int (*upper)(int);
int
main()
{
stringa="cdef";
boolb=none_of(a.begin(),a.end(),(upper)isupper);
cout<return0;
}
这样就行了,为啥vs不用呢,你去观察一下ctype文件就知道了。isupper函数可以唯一确定。
记住 g++ 要用-std=c++0x 或者-std=c++11 (>=4.7)编译选项。
所以gcc需要对isupper进行写莫名奇妙的处理:用其他函数包装之后再传递,或者使用强制类型转换。
typedef int (*upper)(int);
int
main()
{
stringa="cdef";
boolb=none_of(a.begin(),a.end(),(upper)isupper);
cout<return0;
}
这样就行了,为啥vs不用呢,你去观察一下ctype文件就知道了。isupper函数可以唯一确定。
记住 g++ 要用-std=c++0x 或者-std=c++11 (>=4.7)编译选项。
全部回答
- 1楼网友:酒者煙囻
- 2021-03-02 13:26
1. 看来gcc 4.7.2对谓词检查不完全支持~
2.
引用标准的原话:
template< class InputIt, class UnaryPredicate >
bool none_of( InputIt first, InputIt last, UnaryPredicate p );
Checks if unary predicate p returns true for no elements in the range[first, last).
(一元谓词检查是否p返回true的范围内没有任何元素[first, last))
3.
string a = "ABcdef";
bool b = none_of(a.begin(), a.end(), isupper);
就是说如果字符串a中没有大写,则none_of返回true,isupper是检查大写的函数。
2.
引用标准的原话:
template< class InputIt, class UnaryPredicate >
bool none_of( InputIt first, InputIt last, UnaryPredicate p );
Checks if unary predicate p returns true for no elements in the range[first, last).
(一元谓词检查是否p返回true的范围内没有任何元素[first, last))
3.
string a = "ABcdef";
bool b = none_of(a.begin(), a.end(), isupper);
就是说如果字符串a中没有大写,则none_of返回true,isupper是检查大写的函数。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯