在https://github.com/stlab/libraries/blob/main/stlab/concurrency/main_executor.hpp中,我读到
struct main_executor_type {
using result_type = void;
template <typename F>
void operator()(F f) const {
using f_t = decltype(f);
dispatch_async_f(dispatch_get_main_queue(), new f_t(std::move(f)), [](void* f_) {
auto f = static_cast<f_t*>(f_);
(*f)();
delete f;
});
}
};
Run Code Online (Sandbox Code Playgroud)
有什么意义decltype(f),为什么不简单地使用F呢?
我正在尝试使用自定义类型的非类型模板.
struct T {};
template <auto value> struct U {};
template <auto value>
void f (U <value>) {}
int main()
{
constexpr T t;
f (U<1>{}); // OK
f<t> (U<t>{}); // OK
f (U<t>{}); // Error
}
Run Code Online (Sandbox Code Playgroud)
模板参数推断失败,gcc trunk使用-std = c ++ 2a获取
yop.cpp:10:5: note: template argument deduction/substitution failed:
yop.cpp:19:21: note: mismatched types ‘T’ and ‘const T’
19 | f (U<t>{}); // Error
| ^
Run Code Online (Sandbox Code Playgroud)
我错过了什么或这是一个错误吗?
std::ranges::merge(例如)返回包含合并范围结束的一组迭代器,显然,但也包含两个输入范围的结束。Cppreference 说(https://en.cppreference.com/w/cpp/algorithm/ranges)
此外,大多数算法的返回类型已更改为返回在算法执行期间计算的所有潜在有用信息。
返回输入范围的末尾有什么意义?