take_view()
requires default_initializable<V> = default; // (1) C++20
constexpr explicit
take_view(V base, range_difference_t<V> count); // (2) C++20
概要
take_view
オブジェクトを構築する。
- (1) : デフォルト構築
- (2) : 元となるviewと取得する要素数を指定して構築
効果
- (1) :
base_
とcount_
をデフォルト構築する - (2) :
base_
をstd::move(base)
で、count_
をcount
で初期化する
例
#include <iostream>
#include <ranges>
#include <vector>
int main() {
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::ranges::take_view view{vec, 5};
for (const auto& x : view) {
std::cout << x << " ";
}
std::cout << std::endl;
}
出力
1 2 3 4 5
バージョン
言語
- C++20
処理系
- Clang: 13.0.0 ✅
- GCC: 10.1.0 ✅
- ICC: ?
- Visual C++: 2019 Update 10 ✅