Is it possible to make the noexcept function of the auto declaration in a future version of the standard?

The current C ++ standard allows compilers to view the body of a function to obtain information for obtaining a function signature:

template <typename T>
inline auto dereference(T const& pointer) {
    return *pointer;
}

And I wonder if the compiler can automatically declare whether a function is guaranteed if this definition can be seen, perhaps with a syntax like this:

void func() noexcept(auto) {// If all operations in the function are noexcept, the
      // function can be automatically declared noexcept
}

If possible, this will save a lot of difficulty writing a noexcept declaration, especially when writing templates where functions usually follow their definitions when they first appear:

// The noexcept declaration can be even longer than the function body
template <typename T>
void func(T& value) noexcept(
    noexcept(value.member_1()) &&
    noexcept(value.member_2()) &&
    noexcept(value.member_3())
) {
    value.member_1();
    value.member_2();
    value.member_3();
}

// Things will become much easier if the C++ standard support this feature
template <typename T>
void func(T& value) noexcept(auto) {
    value.member_1();
    value.member_2();
    value.member_3();
}

So, can this feature be included in a future version of ISO / IEC 14882?

+4
source share

Source: https://habr.com/ru/post/1614621/


All Articles