std::none_of example from cppreference.com
std::none_of example from cppreference.com
谁能帮我理解这个例子:
v 在这里是一个 std::vector。我认为这里的 std::bind 将其中的内容绑定到函数 std::none_of 因为它是条件。std::modulus取两个参数的mod。但是为什么他们的 _1 和 2 没有下划线。
if (std::none_of(v.cbegin(),
v.cend(),
std::bind(std::modulus<int>(), std::placeholders::_1, 2))) {
std::cout << "None of them are oddn";
}
std::modulus<int>()
是一个接受两个参数的函数对象。
std::bind(std::modulus<int>(), std::placeholders::_1, 2)
创建一个接受一个参数的函数对象。它需要一个参数,因为它只有一个占位符。std::modulus<int>()
的第二个参数绑定到数字 2
。
然后,使用这个新的一元函数对象在v
范围内调用none_of
,在向量中的每个项目上调用它。所以基本上它是检查v
中x
的每个元素的x % 2
。
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- std::async from std::async in windows xp
- std::is_reference from std::any
- std::time_point from and to std::string
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- std::chrono::time_point from std::string
- Visual accept std::string from std::byte iterator
- C++中链表的错误"Abort signal from abort(3) (sigabrt) "
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++ 中的"template <typename From, typename Tag> struct Alias;"是什么?
- from std::vector to adept::avector
- qt get child (Callout) from QChart
- Webassembly from Javascript
- Generate boost::uuids::uuid from boost::compute::detail::sha
- 什么是"Reading unbounded stream from standard input (Memory Management)"的例子
- Calling C++ dll from python
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- std::chrono 在从 main 或 from 类方法使用时给出不同的值
- Calling Python Script from Visual Studio C++ Solution
- std::none_of example from cppreference.com