template<class IndexType, class S>
constexpr auto canonical-slice(S s);
概要
canonical-sliceは、submdspan動作仕様定義で用いられる説明専用の関数テンプレートである。
適格要件
SがIndexTypeのsubmdspanスライス型であること。
効果
以下と等価
if constexpr (is_convertible_v<S, full_extent_t>) {
return static_cast<full_extent_t>(std::move(s));
} else if constexpr (is_convertible_v<S, IndexType>) {
return canonical-index<IndexType>(std::move(s));
} else if constexpr (is-extent-slice<S>) {
return extent_slice{
.offset = canonical-index<IndexType>(std::move(s.offset)),
.extent = canonical-index<IndexType>(std::move(s.extent)),
.stride = canonical-index<IndexType>(std::move(s.stride))
};
} else if constexpr (is-range-slice<S>) {
auto c_first = canonical-index<IndexType>(std::move(s.first));
auto c_last = canonical-index<IndexType>(std::move(s.last));
return canonical-range-slice<IndexType>(
c_first,
canonical-index<IndexType>(c_last - c_first),
canonical-index<IndexType>(std::move(s.stride)));
} else {
auto [s_first, s_last] = std::move(s);
auto c_first = canonical-index<IndexType>(std::move(s_first));
auto c_last = canonical-index<IndexType>(std::move(s_last));
return canonical-range-slice<IndexType>(
c_first,
canonical-index<IndexType>(c_last - c_first));
}
ここでis-extent-sliceは型Sがextent_sliceの特殊化であることを、is-range-sliceは型Sがrange_sliceの特殊化であることを表す説明専用コンセプトとする。
バージョン
言語
- C++26
関連項目
参照
- P3663R3 Future-proof
submdspan_mapping - P3982R2 Split
strided_sliceintoextent_sliceandrange_slicefor C++26- C++26のリリース前に、
extent_sliceのextentメンバ変数が取り出す要素数を表すようになったことで、要素数の計算はcanonical-range-sliceへ委譲されるようになった。あわせてrange_sliceの変換が追加された
- C++26のリリース前に、