gpt4 book ai didi

c++ - `inline` , `constexpr` 或 `noexcept` 仅声明函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:14:04 25 4
gpt4 key购买 nike

对于没有主体的函数,仅用于类型检查目的或在非评估上下文中,是否有任何冒险将此类函数标记为 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 我认为应该没有区别,因为没有标准的方法来检测未计算的表达式是否为常量表达式。但可能有特定于编译器的方法。

关于c++ - `inline` , `constexpr` 或 `noexcept` 仅声明函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57938515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com