C++ Boost库中的none_of_equal()函数位于标头“ boost / algorithm / cxx11 / none_of.hpp ”下,该标头针对参数中传递的值测试序列中的所有元素,如果序列中的所有元素均返回true不等于传递的值。它接受一个序列和一个值,如果没有元素与序列中的值相等,则返回true。
语法:
bool none_of_equal ( InputIterator first, InputIterator last, const &value)
or
bool none_of_equal ( const Range &R, const &value)
参数:该函数接受如下所述的参数:
- first :它指定输入迭代器到序列中的初始位置。
- second :它指定输入迭代器到序列中的最终位置。
- value :它指定一个值,序列中的所有元素均不进行检查。
- R :这是完整的序列。
返回值:如果序列中的所有元素都不等于value,则该函数返回true,否则返回false。
下面是上述方法的实现:
计划1 :
// C++ program to implement the
// above mentioned function
#include
#include
using namespace std;
// Drivers code
int main()
{
// Declares the sequence with
// 5 length and none elements as 1
// [1, 1, 1, 1, 1]
vector c(5, 1);
// Run the function
bool ans
= boost::algorithm::none_of_equal(c, 1);
// Condition to check
if (ans == 1)
cout << "all not equal to 1";
else
cout << "all equals to 1";
return 0;
}
输出:
all equals to 1
计划2 :
// C++ program to implement the
// above mentioned function
#include
#include
using namespace std;
// Drivers code
int main()
{
// Declares the sequence
int a[] = { 1, 2, 5, 6 };
// Run the function
bool ans
= boost::algorithm::none_of_equal(a, a + 4, 4);
// Condition to check
if (ans == 1)
cout << "all not equal to 4";
else
cout << "all equal to 4";
return 0;
}
输出:
all not equal to 4
参考:https://www.boost.org/doc/libs/1_70_0/libs/algorithm/doc/html/the_boost_algorithm_library/CXX11/none_of.html
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。