Boost logo

Boost :

Subject: Re: [boost] [config] Rethinking feature macros?
From: Gevorg Voskanyan (gevbsd_at_[hidden])
Date: 2017-11-06 15:55:55

On 11/06/17 05:15, Peter Dimov via Boost wrote:
> For a concrete example, let's take noexcept in function types. This is
> __cpp_noexcept_function_type, and is implemented by g++ 7, clang 4,
> clang 5 (in C++17 mode), and apparently in the latest VS2017 preview.
> noexcept function pointers break Boost.Bind, and to fix it, I need to
> add overloads for them, but only if they are implemented, otherwise
> the overloads would be an error.

Not really addressing the main question, but just out of curiosity, what
would be the downside of not relying on any macro but detecting the
feature automatically? For example, something like this could be done:

void n() noexcept {}
void e() {}

constexpr bool noexcept_function_type = !std::is_same< decltype( n ),
decltype( e ) >::value;

Now we can use this to SFINAE out the noexcept overloads when they'd be

template < typename R >
R invoke0( R (*f)() )
     std::cout << "main overload" << std::endl;
     return f();

template < typename R >
std::enable_if_t< noexcept_function_type, R >
invoke0( R (*f)() noexcept )
     std::cout << "noexcept overload" << std::endl;
     return f();

void f1()
     std::cout << "f1" << std::endl;

void f2() noexcept
     std::cout << "f2" << std::endl;

int main()
     invoke0( f1 );
     invoke0( f2 );

Clang gives a warning for the noexcept overload in C++14 mode: "mangled
name of 'invoke0' will
       change in C++17 due to non-throwing exception specification in
       signature [-Wc++17-compat-mangling]", but that can be silenced by
surrounding that overload with

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++17-compat-mangling"


#pragma clang diagnostic pop

Didn't try with other compilers.


Boost list run by bdawes at, gregod at, cpdaniel at, john at