命名空间
变体
操作

iter_move(std::counted_iterator)

来自 cppreference.cn
 
 
迭代器库
迭代器概念
迭代器原语
算法概念和工具
间接可调用概念
通用算法要求
(C++20)
(C++20)
(C++20)
实用工具
(C++20)
迭代器适配器
范围访问
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
 
friend constexpr decltype(auto) iter_move( const std::counted_iterator& i )

    noexcept(noexcept(ranges::iter_move(i.base())))

        requires std::input_iterator<I>;
(自 C++20 起)

将解引用底层迭代器的结果强制转换为其关联的右值引用类型。

函数体等效于 return ranges::iter_move(i.base());

此函数对于普通的非限定查找限定查找不可见,并且只能通过实参依赖查找std::counted_iterator<I> 是实参的关联类时找到。

如果 i.count() 等于 0,则行为未定义。

目录

[编辑] 参数

i - 源迭代器适配器

[编辑] 返回值

一个右值引用或一个纯右值临时对象。

[编辑] 复杂度

常数。

[编辑] 示例

#include <iomanip>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
 
void print(auto const& rem, auto const& v)
{
    std::cout << rem << '[' << size(v) << "] {";
    for (char comma[]{0, ' ', 0}; auto const& s : v)
        std::cout << comma << std::quoted(s), *comma = ',';
    std::cout << "}\n";
}
 
int main()
{
    std::vector<std::string> p{"Alpha", "Bravo", "Charlie"}, q;
    print("p", p);
    print("q", q);
 
    using RI = std::counted_iterator<std::vector<std::string>::iterator>;
 
    for (RI iter{p.begin(), 2}; iter != std::default_sentinel; ++iter)
        q.emplace_back(/* ADL */ iter_move(iter));
 
    print("p", p);
    print("q", q);
}

可能的输出

p[3] {"Alpha", "Bravo", "Charlie"}
q[0] {}
p[3] {"", "", "Charlie"}
q[2] {"Alpha", "Bravo"}

[编辑] 缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 应用于 已发布的行为 正确的行为
LWG 3953 C++20 返回类型为 std::iter_rvalue_reference_t<I> 更改为 decltype(auto)

[编辑] 参见

(C++20)
将解引用对象的结果强制转换为其关联的右值引用类型
(自定义点对象)[编辑]
(C++20)
交换两个底层迭代器指向的对象
(函数模板) [编辑]
(C++11)
将实参转换为 xvalue
(函数模板) [编辑]
如果移动构造函数不抛出异常,则将实参转换为 xvalue
(函数模板) [编辑]
(C++11)
转发函数实参并使用类型模板实参来保留其值类别
(函数模板) [编辑]
将某个范围的元素移动到新的位置
(算法函数对象)[编辑]
以向后顺序将某个范围的元素移动到新的位置
(算法函数对象)[编辑]