ev-stdexec-template-lambda-transform-001¶
| 字段 | 值 |
|---|---|
| 项目 | NVIDIA/stdexec |
| 固定 commit | 6d7ad689f4d4 |
| 路径 | include/stdexec/__detail/__let.hpp |
| 行段 | L546-L560 |
| 特性 | 模板 lambda(template lambda) |
| 许可证 | Apache-2.0 |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-26 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
用带类型参数包的模板 lambda 在编译期选择 let 发送者的完成签名
为什么典型¶
模板 lambda 把通常需要独立函数模板或类模板的编译期分支放进局部表达式,直接操作类型包并返回不同的完成签名。
摘录¶
template <class _Fun, class _Child, class... _Env>
static constexpr auto __transform_cmplsig = //
[]<class... _As>(__set_t (*)(_As...), __completion_info __info) //
-> decltype(auto)
{
if constexpr (!__decay_copyable<_As...>)
{
using __what_t = __not_decay_copyable_error_t<_LetTag, _As...>;
return STDEXEC::__throw_compile_time_error(__what_t());
}
else if constexpr (!__invocable<_Fun, __decay_t<_As>&...>)
{
using __what_t = __callable_error_t<_LetTag, _Fun, __decay_t<_As>&...>;
return STDEXEC::__throw_compile_time_error(__what_t());
}
备注¶
生产路径;__transform_cmplsig 是按签名分派的编译期转换器,模板参数包与 if constexpr 配合使用。