Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added noexcept variants to function traits #298

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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