相关疑难解决方法(0)

如何编写启用ADL的尾随返回类型或noexcept规范?

想象一下,我正在写一些容器模板或其他东西.现在是时候专注std::swap于它了.作为一个好公民,我会通过这样的方式启用ADL:

template <typename T>
void swap(my_template<T>& x, my_template<T>& y) {
    using std::swap;
    swap(x.something_that_is_a_T, y.something_that_is_a_T);
}
Run Code Online (Sandbox Code Playgroud)

这非常整洁.直到我想添加一个异常规范.我swapnoexcept只要调换Tnoexcept.所以,我会写一些类似的东西:

template <typename T>
void swap(my_template<T>& x, my_template<T>& y)
    noexcept(noexcept(swap(std::declval<T>(), std::declval<T>())))
Run Code Online (Sandbox Code Playgroud)

问题是,swap在那里需要ADL发现swapstd::swap.我该如何处理?

c++ noexcept argument-dependent-lookup c++11

46
推荐指数
3
解决办法
1151
查看次数

标签 统计

argument-dependent-lookup ×1

c++ ×1

c++11 ×1

noexcept ×1