ev-stdexec-copy-elision-trait-001¶
| 字段 | 值 |
|---|---|
| 项目 | NVIDIA/stdexec |
| 固定 commit | 6d7ad689f4d4 |
| 路径 | include/stdexec/__detail/__basic_sender.hpp |
| 行段 | L80-L88 |
| 特性 | 保证的复制消除 |
| 许可证 | Apache-2.0 |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-27 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
在 requires 表达式中直接用函数返回的 prvalue 初始化不可移动类型
为什么典型¶
约束的满足依赖 C++17 强制复制消除:目标类型删除了移动构造,只有 prvalue 直接初始化才能成立。
摘录¶
// A decay_copyable trait that uses C++17 guaranteed copy elision, so
// that __decay_copyable_if<immovable_type> is satisfied.
template <class _Ty, class _Uy = __decay_t<_Ty>>
concept __decay_copyable_if = requires(__declfn_t<_Ty> __val) { _Uy(__val()); };
template <class _Ty, class _Uy = __decay_t<_Ty>>
concept __nothrow_decay_copyable_if = requires(__declfn_t<_Ty> __val) {
{ _Uy(__val()) } noexcept;
};
备注¶
生产路径;用于判定 decay-copyable 是否成立,注释明确说明依赖强制复制消除。