operator-(std::counted_iterator<I>, std::default_sentinel_t)
來自 cppreference.com
friend constexpr std::iter_difference_t<I> operator-( const counted_iterator& x, std::default_sentinel_t ); |
(1) | (C++20 起) |
friend constexpr std::iter_difference_t<I> operator-( std::default_sentinel_t, const counted_iterator& y ); |
(2) | (C++20 起) |
1) 返回到末尾的負距離。
2) 返回到末尾的正距離。
此函式模板對於普通的非限定或限定查詢不可見,只能透過實參依賴查詢在 std::counted_iterator<I> 是實參的關聯類時找到。
目錄 |
[編輯] 引數
x, y | - | 要計算差異的迭代器介面卡 |
[編輯] 返回值
1) -x.count()
2) y.count()
[編輯] 示例
執行此程式碼
#include <initializer_list> #include <iterator> int main() { constexpr static auto v = {1, 2, 3, 4}; constexpr std::counted_iterator<std::initializer_list<int>::iterator> it{v.begin(), 3}; constexpr auto d1 = it - std::default_sentinel; static_assert(d1 == -3); // (1) constexpr auto d2 = std::default_sentinel - it; static_assert(d2 == +3); // (2) }
[編輯] 參閱
遞增或遞減 counted_iterator (public member function) | |
(C++20) |
前進迭代器 (function template) |
(C++20) |
計算兩個迭代器介面卡之間的距離 (function template) |
(C++20) |
用於知道其範圍邊界的迭代器的預設哨兵 (class) |