Zizheng Tai Zizheng Tai - 6 months ago 29
C++ Question

noexcept to become part of the type system

I hear that

will become part of the function type in C++17. What difference will this make? Does it mean that we will have to distinguish between
and non-
functions and member functions in our templates (which will double the amount of boilerplate code we have to write)?

For example, for current templates that matches function pointers:

template<typename R, typename... Args>
struct Foo<R (*)(Args...)> {};

We will need an additional:

template<typename R, typename... Args>
struct Foo<R (*)(Args...) noexcept> {};

And this is only for good old functions. For member functions we have
, and ref-qualifiers already, yielding a huge load of combinatuons. With the addition of
it will get twice as bad.


If they had blindly changed things so that noexcept qualifications were part of a function pointer's type, they would have broken tons of code, generic and not. As such, there's a back-door.

In accord with P0021R1, any pointer to a noexcept-qualified function can be implicitly converted to a pointer to a non-noexcept-qualified function. The same goes for pointers to member functions with such qualifications.

Indeed, building that loophole seems to be what around 2/3rds of the language in the proposal is for.