GeezerVison is showing cpprefjp.github.io — std::ranges::includes - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<algorithm>
std::ranges:: includes (C++20)
namespace std :: ranges {
template < input_iterator I1 ,
sentinel_for < I1 > S1 ,
input_iterator I2 ,
sentinel_for < I2 > S2 ,
class Proj1 = identity ,
class Proj2 = identity ,
indirect_strict_weak_order <
projected < I1 , Proj1 > ,
projected < I2 , Proj2 >
> Comp = ranges::less >
constexpr bool
includes ( I1 first1 ,
S1 last1 ,
I2 first2 ,
S2 last2 ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (1) C++20
template < input_range R1 ,
input_range R2 ,
class Proj1 = identity ,
class Proj2 = identity ,
indirect_strict_weak_order <
projected < iterator_t < R1 > , Proj1 > ,
projected < iterator_t < R2 > , Proj2 >
> Comp = ranges::less >
constexpr bool
includes ( R1 && r1 ,
R2 && r2 ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (2) C++20
template < execution-policy Ep ,
random_access_iterator I1 ,
sized_sentinel_for < I1 > S1 ,
random_access_iterator I2 ,
sized_sentinel_for < I2 > S2 ,
class Proj1 = identity ,
class Proj2 = identity ,
indirect_strict_weak_order <
projected < I1 , Proj1 > ,
projected < I2 , Proj2 >
> Comp = ranges::less >
bool
includes ( Ep && exec ,
I1 first1 ,
S1 last1 ,
I2 first2 ,
S2 last2 ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (3) C++26
template < execution-policy Ep ,
sized-random-access-range R1 ,
sized-random-access-range R2 ,
class Proj1 = identity ,
class Proj2 = identity ,
indirect_strict_weak_order <
projected < iterator_t < R1 > , Proj1 > ,
projected < iterator_t < R2 > , Proj2 >
> Comp = ranges::less >
bool
includes ( Ep && exec ,
R1 && r1 ,
R2 && r2 ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (4) C++26
}
概要
2つのソート済み範囲において、一方の範囲の要素がもう一方の範囲に全て含まれているかを判定する。
(1): イテレータ範囲を指定する
(2): Rangeを直接指定する
(3): (1)の並列アルゴリズム版。実行ポリシーを指定する
(4): (2)の並列アルゴリズム版。実行ポリシーを指定する
戻り値
[first2,last2) が empty であるか、[first2,last2) の全ての要素が [first1,last1) に含まれている場合は true、そうでない場合は false を返す。
計算量
最大で 2 * ((last1 - first1) + (last2 - first2)) - 1 回比較する
例
基本的な使い方
#include <iostream>
#include <set>
#include <algorithm>
int main ()
{
std::set < int > a = { 1 , 2 , 3 , 4 , 5 , 6 };
std::set < int > b = { 2 , 4 , 6 };
std::set < int > c = { 2 , 4 , 7 };
std::cout << std::boolalpha ;
std::cout << std::ranges::includes ( a , b ) << std::endl ;
std::cout << std::ranges::includes ( a , c ) << std::endl ;
}
出力
true
false
並列アルゴリズムの例 (C++26)
#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>
int main ()
{
std::vector < int > a = { 1 , 2 , 3 , 4 , 5 , 6 };
std::vector < int > b = { 2 , 4 , 6 };
std::vector < int > c = { 2 , 4 , 7 };
std::cout << std::boolalpha ;
// 並列にaがbの全要素を含むか判定する
std::cout << std::ranges::includes ( std::execution::par , a , b ) << std::endl ;
std::cout << std::ranges::includes ( std::execution::par , a , c ) << std::endl ;
}
出力
true
false
バージョン
言語
処理系
参照