ABu
ABu

Reputation: 12279

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

For functions that has no body, and are just used for type-checking purposes or in non-evaluated contexts, is there any adventage to mark such functions as inline, noexcept or constexpr? For example:

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; }

Does these constexpr or noexcept mean something or have any effect at all in any sense? I guess that it could even be misleading, because the user could understand these functions could have a definition somewhere else. Anyway, is there any naming convention to mark that these functions are meant to be used in non-evaluated contexts only, or whose purpose is just to calculate types?

Upvotes: 4

Views: 146

Answers (1)

Sebastian Redl
Sebastian Redl

Reputation: 71989

noexcept definitely makes a difference, since you could use the functions in unevaluated noexcept contexts.

inline is irrelevant. It only affects linkage of the implementation, and there is no implementation.

constexpr should, I think, make no difference, since there is no standard way of detecting whether an unevaluated expression is a constant expression. But there might be compiler-specific ways of doing it.

Upvotes: 1

Related Questions