std::experimental::apply requires a constexpr implementation of INVOKE(...). Simply marking the current implementation of __invoke as constexpr will break existing code due to CWG issue #1581. For this reason we should add a separate function called __invoke_constexpr to be used where constexpr is required.
To supply two almost identical INVOKE(...) we use the <__invoke> header to generate the declarations and definitions by defining the required macros and including the <__invoke> header inline. The <__invoke> header can be included multiple times.
The macros used are:
- _LIBCPP_INVOKE_NAME: The name of the invoke function to be created.
- _LIBCPP_INVOKE_CONSTEXPR: The optional constexpr decorator for the invoke function.
- _LIBCPP_DECLARE_INVOKE: Declare the required invoke function.
- _LIBCPP_DEFINE_INVOKE: Define the required invoke function.
I chose not to generate invoke functions using macros because of the amount of code that would have to be within a macro block. It also is likely to yield bad error messages.
This patch also re-enables constexpr support for std::experimental::apply.
Also See:
https://llvm.org/bugs/show_bug.cgi?id=23141
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1581