最終更新日時:
が更新

履歴 編集

function template
<mdspan>

canonical-slice(C++26)

template<class IndexType, class S>
constexpr auto canonical-slice(S s);

概要

canonical-sliceは、submdspan動作仕様定義で用いられる説明専用の関数テンプレートである。

適格要件

SIndexTypesubmdspanスライス型であること。

効果

以下と等価

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は型Sextent_sliceの特殊化であることを、is-range-sliceは型Srange_sliceの特殊化であることを表す説明専用コンセプトとする。

バージョン

言語

  • C++26

関連項目

参照