我試圖使用greater_equal predicate
和includes() algorithm
。我寫了下面的代碼:如何在includes()算法中使用greater_equal謂詞?
#include <iostream>
#include <algorithm>
#include <functional>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 9, 10};
int b[] = {4, 3, 5, 1, 2, 6, 8, 9, 7, 10, 11};
unsigned int alen = sizeof(a)/sizeof(int), blen = sizeof(b)/sizeof(int);
std::sort(a, a + alen);
std::sort(b, b + blen);
if(std::includes(a, a + alen, b, b + blen, std::greater_equal<int>()))
std::cout << "a contains b" << std::endl;
}
我期待這將輸出a contains b
因爲謂語greater_equal predicate
應該滿足於b
是在a
的所有元素,但事實並非如此。我對它的用法有點困惑。請幫忙。
[「第二個版本期望它們使用給定的比較函數'comp'進行排序。」](http://en.cppreference.com/w/cpp/algorithm/includes)數組不排序尊重你的比較)。 – BoBTFish