Skip to content

Latest commit

 

History

History
78 lines (62 loc) · 2.55 KB

ranges_includes.md

File metadata and controls

78 lines (62 loc) · 2.55 KB

includes

  • algorithm[meta header]
  • std::ranges[meta namespace]
  • function template[meta id-type]
  • cpp20[meta cpp]
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)

  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 ranges::includes(R1&& r1, R2&& r2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});                 // (2)
}
  • input_iterator[link /reference/iterator/input_iterator.md]
  • sentinel_for[link /reference/iterator/sentinel_for.md]
  • indirect_strict_weak_order[link /reference/iterator/indirect_strict_weak_order.md]
  • projected[link /reference/iterator/projected.md]
  • ranges::less[link /reference/functional/ranges_less.md]
  • identity[link /reference/functional/identity.md]
  • input_range[link /reference/ranges/input_range.md]
  • iterator_t[link /reference/ranges/iterator_t.md]

概要

2つのソート済み範囲において、一方の範囲の要素がもう一方の範囲に全て含まれているかを判定する。

  • (1): イテレータペアで範囲を指定する
  • (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;
}
  • std::ranges::includes[color ff0000]

出力

true
false

バージョン

言語

  • C++20

処理系

参照