Skip to content

Commit

Permalink
Added noexcept variants to function traits (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuSo58 authored Apr 5, 2024
1 parent 1cd179d commit 0b5d720
Show file tree
Hide file tree
Showing 3 changed files with 407 additions and 2 deletions.
136 changes: 135 additions & 1 deletion include/fplus/function_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ namespace utils {
};
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
};

#endif

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType (*)(Args...)>
: public function_traits<ReturnType(Args...)> {
Expand Down Expand Up @@ -174,6 +183,39 @@ namespace utils {
typedef const volatile ClassType& owner_type;
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType (*)(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
typedef ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) const noexcept>
: public function_traits<ReturnType(Args...)> {
typedef const ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) volatile noexcept>
: public function_traits<ReturnType(Args...)> {
typedef volatile ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) const volatile noexcept>
: public function_traits<ReturnType(Args...)> {
typedef const volatile ClassType& owner_type;
};

#endif

template <typename FunctionType>
struct function_traits<std::function<FunctionType>>
: public function_traits<FunctionType> {
Expand All @@ -188,7 +230,7 @@ namespace utils {
#ifdef MEM_FN_SYMBOL_XX0SL7G4Z0J

template <typename R, typename C>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R C::*>>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)()>>
: public function_traits<R(C*)> {
};
template <typename R, typename C, typename... A>
Expand All @@ -207,6 +249,28 @@ namespace utils {
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const volatile>>
: public function_traits<R(const volatile C*, A...)> {
};
#if __cplusplus > 201510L
template <typename R, typename C>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)() noexcept>>
: public function_traits<R(C*)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) noexcept>>
: public function_traits<R(C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const noexcept>>
: public function_traits<R(const C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) volatile noexcept>>
: public function_traits<R(volatile C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const volatile noexcept>>
: public function_traits<R(const volatile C*, A...)> {
};
#endif

#undef MEM_FN_SYMBOL_XX0SL7G4Z0J
#endif
Expand Down Expand Up @@ -418,6 +482,76 @@ namespace internal {
template <typename FunctionType>
struct has_function_traits<std::function<FunctionType>> : std::true_type {
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct has_function_traits<ReturnType(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename... Args>
struct has_function_traits<ReturnType (*)(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) & noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile && noexcept>
: std::true_type {
};

#endif
}
}

Expand Down
136 changes: 135 additions & 1 deletion include_all_in_one/include/fplus/fplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@ namespace utils {
};
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
};

#endif

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType (*)(Args...)>
: public function_traits<ReturnType(Args...)> {
Expand Down Expand Up @@ -433,6 +442,39 @@ namespace utils {
typedef const volatile ClassType& owner_type;
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct function_traits<ReturnType (*)(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) noexcept>
: public function_traits<ReturnType(Args...)> {
typedef ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) const noexcept>
: public function_traits<ReturnType(Args...)> {
typedef const ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) volatile noexcept>
: public function_traits<ReturnType(Args...)> {
typedef volatile ClassType& owner_type;
};

template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType (ClassType::*)(Args...) const volatile noexcept>
: public function_traits<ReturnType(Args...)> {
typedef const volatile ClassType& owner_type;
};

#endif

template <typename FunctionType>
struct function_traits<std::function<FunctionType>>
: public function_traits<FunctionType> {
Expand All @@ -447,7 +489,7 @@ namespace utils {
#ifdef MEM_FN_SYMBOL_XX0SL7G4Z0J

template <typename R, typename C>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R C::*>>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)()>>
: public function_traits<R(C*)> {
};
template <typename R, typename C, typename... A>
Expand All @@ -466,6 +508,28 @@ namespace utils {
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const volatile>>
: public function_traits<R(const volatile C*, A...)> {
};
#if __cplusplus > 201510L
template <typename R, typename C>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)() noexcept>>
: public function_traits<R(C*)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) noexcept>>
: public function_traits<R(C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const noexcept>>
: public function_traits<R(const C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) volatile noexcept>>
: public function_traits<R(volatile C*, A...)> {
};
template <typename R, typename C, typename... A>
struct function_traits<MEM_FN_SYMBOL_XX0SL7G4Z0J<R (C::*)(A...) const volatile noexcept>>
: public function_traits<R(const volatile C*, A...)> {
};
#endif

#undef MEM_FN_SYMBOL_XX0SL7G4Z0J
#endif
Expand Down Expand Up @@ -677,6 +741,76 @@ namespace internal {
template <typename FunctionType>
struct has_function_traits<std::function<FunctionType>> : std::true_type {
};

#if __cplusplus > 201510L

template <typename ReturnType, typename... Args>
struct has_function_traits<ReturnType(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename... Args>
struct has_function_traits<ReturnType (*)(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) & noexcept> : std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile & noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) volatile && noexcept>
: std::true_type {
};

template <typename ReturnType, typename ClassType, typename... Args>
struct has_function_traits<ReturnType (ClassType::*)(Args...) const volatile && noexcept>
: std::true_type {
};

#endif
}
}

Expand Down
Loading

0 comments on commit 0b5d720

Please sign in to comment.