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

履歴 編集

function
<ranges>

std::ranges::iota_view::size(C++20)

constexpr auto size() const
  requires (same_as<W, Bound> && advanceable<W>) || (integral<W> && integral<Bound>) || sized_sentinel_for<Bound, W>;

概要

iota_viewの大きさを取得する。

この関数は、iota_viewsized_rangeのときのみオーバーロード解決に参加する。

効果

if constexpr (is-integer-like<W> && is-integer-like<Bound>)
  return (value_ < 0)
    ? ((bound_ < 0)
      ? to-unsigned-like(-value_) - to-unsigned-like(-bound_)
      : to-unsigned-like(bound_) + to-unsigned-like(-value_))
    : to-unsigned-like(bound_) - to-unsigned-like(value_);
else
  return to-unsigned-like(bound_ - value_);

to-unsigned-likeは、処理系定義の型(例えば128ビット整数など)も含めて、符号なし整数へ変換する説明専用の関数。

#include <ranges>

int main()
{
  constexpr std::ranges::iota_view iota{0, 5};
  static_assert(iota.size() == 5);
  static_assert(std::same_as<decltype(iota.size()), unsigned int>);
}

出力

バージョン

言語

  • C++20

処理系

参照