From 23c1c83cdf1039d80bb7087980ab353003f00c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Horsk=C3=BD?= Date: Thu, 4 Apr 2024 17:27:21 +0200 Subject: [PATCH 1/5] Added noexcept variants to function traits --- include/fplus/function_traits.hpp | 122 +++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index b2e39b1f..c2105200 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -145,6 +145,11 @@ namespace utils { }; }; + template + struct function_traits + : public function_traits { + }; + template struct function_traits : public function_traits { @@ -174,6 +179,35 @@ namespace utils { typedef const volatile ClassType& owner_type; }; + template + struct function_traits + : public function_traits { + }; + + template + struct function_traits + : public function_traits { + typedef ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef const ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef volatile ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef const volatile ClassType& owner_type; + }; + template struct function_traits> : public function_traits { @@ -188,7 +222,7 @@ namespace utils { #ifdef MEM_FN_SYMBOL_XX0SL7G4Z0J template - struct function_traits> + struct function_traits> : public function_traits { }; template @@ -207,6 +241,26 @@ namespace utils { struct function_traits> : public function_traits { }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; #undef MEM_FN_SYMBOL_XX0SL7G4Z0J #endif @@ -418,6 +472,72 @@ namespace internal { template struct has_function_traits> : std::true_type { }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; } } From cb397d701979f3ee79052414f5f1c410f3db1e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Horsk=C3=BD?= Date: Thu, 4 Apr 2024 17:44:55 +0200 Subject: [PATCH 2/5] Added tests --- test/function_traits_test.cpp | 137 ++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/test/function_traits_test.cpp b/test/function_traits_test.cpp index f2092700..ff43279b 100644 --- a/test/function_traits_test.cpp +++ b/test/function_traits_test.cpp @@ -21,13 +21,25 @@ std::string CcI2SFree(const std::string& str, int x) return str + std::to_string(x); } +std::string CcI2SFreeNoexcept(const std::string& str, int x) noexcept +{ + return str + std::to_string(x); +} + auto CcI2SLambda = [](const std::string& str, int x) { return CcI2SFree(str, x); }; +auto CcI2SLambdaNoexcept = [](const std::string& str, int x) noexcept { return CcI2SFree(str, x); }; + std::function CcI2SStdFunction = CcI2SLambda; +std::function + CcI2SStdFunctionNoexcept = CcI2SLambdaNoexcept; + std::string (*CcI2SFunctionPointer)(const std::string&, int) = &CcI2SFree; +std::string (*CcI2SFunctionPointerNoexcept)(const std::string&, int) noexcept = &CcI2SFreeNoexcept; + struct CcI2SStrct { std::string operator()(const std::string& str, int x) { @@ -47,6 +59,25 @@ struct CcI2SStrct { } }; +struct CcI2SStrctNoexcept { + std::string operator()(const std::string& str, int x) noexcept + { + return CcI2SFreeNoexcept(str, x); + } + std::string nonCMemF(const std::string& str, int x) noexcept + { + return CcI2SFreeNoexcept(str, x); + } + std::string cnstMemF(const std::string& str, int x) const noexcept + { + return CcI2SFreeNoexcept(str, x); + } + static std::string sttcMemF(const std::string& str, int x) noexcept + { + return CcI2SFreeNoexcept(str, x); + } +}; + TEST_CASE("function_traits_test - static_asserts") { using namespace fplus; @@ -102,6 +133,58 @@ TEST_CASE("function_traits_test - static_asserts") std::string>::value, "No."); + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + CcI2SStrct ccI2SStrct; ccI2SStrct("dummy call to avoid unused variable warnings", 0); static_assert(std::is_same< @@ -155,4 +238,58 @@ TEST_CASE("function_traits_test - static_asserts") utils::function_traits::result_type, std::string>::value, "No."); + + CcI2SStrctNoexcept ccI2SStrctNoexcept; + ccI2SStrctNoexcept("dummy call to avoid unused variable warnings", 0); + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); + + static_assert(std::is_same< + utils::function_traits::arg<0>::type, + const std::string&>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::arg<1>::type, + int>::value, + "No."); + static_assert(std::is_same< + utils::function_traits::result_type, + std::string>::value, + "No."); } From b96b618e880b5db9794ed6be8fbf72a05f64c6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Horsk=C3=BD?= Date: Thu, 4 Apr 2024 18:23:01 +0200 Subject: [PATCH 3/5] Added compiler macros and fixed formatting --- include/fplus/function_traits.hpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index c2105200..517cad80 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -145,11 +145,15 @@ namespace utils { }; }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + template struct function_traits : public function_traits { }; +#endif + template struct function_traits : public function_traits { @@ -179,6 +183,8 @@ namespace utils { typedef const volatile ClassType& owner_type; }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + template struct function_traits : public function_traits { @@ -208,6 +214,8 @@ namespace utils { typedef const volatile ClassType& owner_type; }; +#endif + template struct function_traits> : public function_traits { @@ -241,6 +249,7 @@ namespace utils { struct function_traits> : public function_traits { }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) template struct function_traits> : public function_traits { @@ -261,6 +270,7 @@ namespace utils { struct function_traits> : public function_traits { }; +#endif #undef MEM_FN_SYMBOL_XX0SL7G4Z0J #endif @@ -473,6 +483,8 @@ namespace internal { struct has_function_traits> : std::true_type { }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + template struct has_function_traits : std::true_type { }; @@ -501,21 +513,21 @@ namespace internal { }; template - struct has_function_traits : std::true_type { + struct has_function_traits : std::true_type { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; @@ -525,19 +537,21 @@ namespace internal { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; template - struct has_function_traits + struct has_function_traits : std::true_type { }; + +#endif } } From daff6093fc757558b5441e0d75226f99526966ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Horsk=C3=BD?= Date: Thu, 4 Apr 2024 20:06:08 +0200 Subject: [PATCH 4/5] Added generated aio include --- include_all_in_one/include/fplus/fplus.hpp | 136 ++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index bf7363e2..b6cb7628 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -404,6 +404,15 @@ namespace utils { }; }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + + template + struct function_traits + : public function_traits { + }; + +#endif + template struct function_traits : public function_traits { @@ -433,6 +442,39 @@ namespace utils { typedef const volatile ClassType& owner_type; }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + + template + struct function_traits + : public function_traits { + }; + + template + struct function_traits + : public function_traits { + typedef ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef const ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef volatile ClassType& owner_type; + }; + + template + struct function_traits + : public function_traits { + typedef const volatile ClassType& owner_type; + }; + +#endif + template struct function_traits> : public function_traits { @@ -447,7 +489,7 @@ namespace utils { #ifdef MEM_FN_SYMBOL_XX0SL7G4Z0J template - struct function_traits> + struct function_traits> : public function_traits { }; template @@ -466,6 +508,28 @@ namespace utils { struct function_traits> : public function_traits { }; +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; + template + struct function_traits> + : public function_traits { + }; +#endif #undef MEM_FN_SYMBOL_XX0SL7G4Z0J #endif @@ -677,6 +741,76 @@ namespace internal { template struct has_function_traits> : std::true_type { }; + +#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + + template + struct has_function_traits + : std::true_type { + }; + +#endif } } From 7832832f699f31b0af6950d7e117d6df890cedd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Horsk=C3=BD?= Date: Fri, 5 Apr 2024 07:29:45 +0200 Subject: [PATCH 5/5] Changed compiler macros to feature tests --- include/fplus/function_traits.hpp | 8 ++++---- include_all_in_one/include/fplus/fplus.hpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index 517cad80..9598f748 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -145,7 +145,7 @@ namespace utils { }; }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits @@ -183,7 +183,7 @@ namespace utils { typedef const volatile ClassType& owner_type; }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits @@ -249,7 +249,7 @@ namespace utils { struct function_traits> : public function_traits { }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits> : public function_traits { @@ -483,7 +483,7 @@ namespace internal { struct has_function_traits> : std::true_type { }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct has_function_traits : std::true_type { diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index b6cb7628..75b05a6c 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -404,7 +404,7 @@ namespace utils { }; }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits @@ -442,7 +442,7 @@ namespace utils { typedef const volatile ClassType& owner_type; }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits @@ -508,7 +508,7 @@ namespace utils { struct function_traits> : public function_traits { }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct function_traits> : public function_traits { @@ -742,7 +742,7 @@ namespace internal { struct has_function_traits> : std::true_type { }; -#if ((defined(__GNUC__) && __GNUC__ >= 11) || (defined(__clang__) && __clang_major__ >= 16)) && !defined(_MSC_VER) +#if __cplusplus > 201510L template struct has_function_traits : std::true_type {