Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Oct 17, 2023
1 parent e62d4ec commit 981b03e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions include/ylt/thirdparty/cinatra/function_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <type_traits>

// member function
#define TIMAX_FUNCTION_TRAITS(...) \
template <typename ReturnType, typename ClassType, typename... Args> \
struct function_traits_impl<ReturnType (ClassType::*)(Args...) __VA_ARGS__> \
#define TIMAX_FUNCTION_TRAITS(...) \
template <typename ReturnType, typename ClassType, typename... Args> \
struct function_traits_impl<ReturnType (ClassType::*)(Args...) __VA_ARGS__> \
: function_traits_impl<ReturnType(Args...)> {};

namespace timax {
Expand All @@ -22,22 +22,24 @@ namespace timax {
* 6. function with generic operator call ==> template <typeanme ...
* Args> &T::operator()
*/
template <typename T> struct function_traits_impl;
template <typename T>
struct function_traits_impl;

template <typename T>
struct function_traits
: function_traits_impl<std::remove_cv_t<std::remove_reference_t<T>>> {};

template <typename Ret, typename... Args>
struct function_traits_impl<Ret(Args...)> {
public:
public:
enum { arity = sizeof...(Args) };
typedef Ret function_type(Args...);
typedef Ret result_type;
using stl_function_type = std::function<function_type>;
typedef Ret (*pointer)(Args...);

template <size_t I> struct args {
template <size_t I>
struct args {
static_assert(I < arity,
"index is out of range, index must less than sizeof Args");
using type = typename std::tuple_element<I, std::tuple<Args...>>::type;
Expand Down Expand Up @@ -73,22 +75,22 @@ struct function_traits_impl
: function_traits_impl<decltype(&Callable::operator())> {};

template <typename Function>
typename function_traits<Function>::stl_function_type
to_function(const Function &lambda) {
typename function_traits<Function>::stl_function_type to_function(
const Function &lambda) {
return static_cast<typename function_traits<Function>::stl_function_type>(
lambda);
}

template <typename Function>
typename function_traits<Function>::stl_function_type
to_function(Function &&lambda) {
typename function_traits<Function>::stl_function_type to_function(
Function &&lambda) {
return static_cast<typename function_traits<Function>::stl_function_type>(
std::forward<Function>(lambda));
}

template <typename Function>
typename function_traits<Function>::pointer
to_function_pointer(const Function &lambda) {
typename function_traits<Function>::pointer to_function_pointer(
const Function &lambda) {
return static_cast<typename function_traits<Function>::pointer>(lambda);
}
} // namespace timax
} // namespace timax

0 comments on commit 981b03e

Please sign in to comment.