Files
HQueue/include/internal/lambda_traits.hpp
T
2026-04-05 21:37:35 +04:00

35 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Credits to DeepSeek - I'm NOT writing all thatt
#pragma once
#include <tuple>
#include <type_traits>
// Primary template will use the operator() of the callable
template <typename T>
struct function_traits : function_traits<decltype(&T::operator())> {};
// Specialization for function pointers
template <typename R, typename... Args>
struct function_traits<R(*)(Args...)> {
using return_type = R;
using argument_types = std::tuple<Args...>;
static constexpr std::size_t arity = sizeof...(Args);
};
// Specialization for const member function pointers (lambdas & functors)
template <typename C, typename R, typename... Args>
struct function_traits<R(C::*)(Args...) const> {
using return_type = R;
using argument_types = std::tuple<Args...>;
static constexpr std::size_t arity = sizeof...(Args);
};
// Specialization for nonconst member function pointers (rare for lambdas)
template <typename C, typename R, typename... Args>
struct function_traits<R(C::*)(Args...)> {
using return_type = R;
using argument_types = std::tuple<Args...>;
static constexpr std::size_t arity = sizeof...(Args);
};