"inline"、"constexpr"或"noexcept"

`inline`, `constexpr` or `noexcept` for declaration only functions

本文关键字:quot noexcept inline constexpr      更新时间:2023-10-16

对于没有主体的函数,仅用于类型检查目的或未计算的上下文,是否有任何机会将此类函数标记为inlinenoexceptconstexpr?例如:

namespace _detail {
template<class R, class T, class... Params>
constexpr R result_type(R(T::*)(Params...)) noexcept;
template<class R, class T, class... Params>
constexpr R result_type(R(T::*)(Params...) const) noexcept;
template<class R, class... Params>
constexpr R result_type(R(*)(Params...)) noexcept;
template<class R, class... Params>
constexpr R result_type(R(&)(Params...)) noexcept;
}
template<class F>
struct result_type { typedef decltype(_detail::result_type(declval<F>())) type; }

这些constexprnoexcept在任何意义上是否意味着什么或有任何影响? 我想它甚至可能具有误导性,因为用户可以理解这些功能可能在其他地方有定义。无论如何,是否有任何命名约定来标记这些函数仅用于非计算上下文,或者其目的只是计算类型?

noexcept肯定会有所作为,因为您可以在未计算的noexcept上下文中使用这些函数。

inline无关紧要。只影响实现的联动,没有实现。

我认为constexpr应该没有什么区别,因为没有标准方法来检测未计算的表达式是否是常量表达式。但是可能有特定于编译器的方法。