最終更新日時(UTC):
が更新

履歴 編集

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-strided-slice<S>) {
  auto c_extent = canonical-index<IndexType>(std::move(s.extent));
  auto c_offset = canonical-index<IndexType>(std::move(s.offset));
  if constexpr (is_same_v<decltype(c_extent), constant_wrapper<IndexType(0)>>) {
    return strided_slice{
      .offset = c_offset,
      .extent = c_extent,
      .stride = cw<IndexType(1)>
    };
  } else {
    return strided_slice{
      .offset = c_offset,
      .extent = c_extent,
      .stride = 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 strided_slice{
    .offset = c_first,
    .extent = canonical-index<IndexType>(c_last - c_first),
    .stride = cw<IndexType(1)>
  };
}

ここでis-strided-sliceは、型Sstrided_sliceの特殊化であることを表す説明専用コンセプトとする。

バージョン

言語

  • C++26

関連項目

参照