Date: Tue, 20 May 2025 09:17:32 +0100
On Tue, 20 May 2025, 09:01 Jonathan Wakely, <cxx_at_[hidden]> wrote:
>
>
> On Tue, 20 May 2025, 08:46 Frederick Virchanza Gotham via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> Sometimes we write a function without any intention of it ever being
>> invoked.
>
>
> I do this often, but in all cases where I've done this it can be
> consteval, and it's with an auto or decltype(auto) return type.
>
>
> Consider the following function to get a function's return
>> type:
>>
>> template <typename ReturnType, typename... Params>
>> ReturnType ToReturnType( ReturnType (*)(Params...) )
>> {
>> // empty function body
>> }
>>
>
> If the function body is empty then it can typically be a variable template
> or an alias template. Or have no function body at all. You don't need to
> define it if you're not calling it.
>
#include <type_traits>
template<typename T>
constexpr std::nullptr_t ReturnTypeOf_v{};
template<typename R, typename... Args>
constexpr auto ReturnTypeOf_v<R(*)(Args...)> = std::type_identity<R>{};
template<typename R, typename... Args>
constexpr auto ReturnTypeOf_v<R(&)(Args...)> = std::type_identity<R>{};
template<auto T>
using ReturnTypeOf = typename decltype(ReturnTypeOf_v<decltype(T)>)::type;
>
>
> On Tue, 20 May 2025, 08:46 Frederick Virchanza Gotham via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> Sometimes we write a function without any intention of it ever being
>> invoked.
>
>
> I do this often, but in all cases where I've done this it can be
> consteval, and it's with an auto or decltype(auto) return type.
>
>
> Consider the following function to get a function's return
>> type:
>>
>> template <typename ReturnType, typename... Params>
>> ReturnType ToReturnType( ReturnType (*)(Params...) )
>> {
>> // empty function body
>> }
>>
>
> If the function body is empty then it can typically be a variable template
> or an alias template. Or have no function body at all. You don't need to
> define it if you're not calling it.
>
#include <type_traits>
template<typename T>
constexpr std::nullptr_t ReturnTypeOf_v{};
template<typename R, typename... Args>
constexpr auto ReturnTypeOf_v<R(*)(Args...)> = std::type_identity<R>{};
template<typename R, typename... Args>
constexpr auto ReturnTypeOf_v<R(&)(Args...)> = std::type_identity<R>{};
template<auto T>
using ReturnTypeOf = typename decltype(ReturnTypeOf_v<decltype(T)>)::type;
Received on 2025-05-20 08:17:50