一:功能
给定两个有序序列V1, V2;判断V2 中的所有元素是否都在 V1 内 。
二:用法
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
int main() {
std::vector<char> letters('z'-'a'+1,'\0');
std::iota(letters.begin(), letters.end(), 'a');
for(auto l : letters)
{
std::cout << l << " ";
}
std::cout << std::endl;
std::string input = "the quick brown fox jumps over the lazy dog";
std::ranges::sort(input);
for(auto i : input)
{
std::cout << i << " ";
}
std::cout << std::endl;
bool test = std::ranges::includes(input, letters);
std::cout << std::boolalpha << "test == " << test << "\n";
}
// includes algorithm example
#include <iostream> // std::cout
#include <algorithm> // std::includes, std::sort
bool myfunction (int i, int j) { return i<j; }
int main () {
int container[] = {5,10,15,20,25,30,35,40,45,50};
int continent[] = {40,30,20,10};
std::sort (container,container+10);
std::sort (continent,continent+4);
// using default comparison:
if ( std::includes(container,container+10,continent,continent+4) )
std::cout << "container includes continent!\n";
// using myfunction as comp:
if ( std::includes(container,container+10,continent,continent+4, myfunction) )
std::cout << "container includes continent!\n";
return 0;
}