From 916337a5727b5a53302467f443b9207673d3d988 Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:06:12 -0400 Subject: [PATCH 1/7] changed fplus::internal::get_index to reduce templated recursion and introduced contains metafunction to test whether type list contains a type --- include/fplus/variant.hpp | 27 +++++++++---------- include_all_in_one/include/fplus/fplus.hpp | 31 ++++++++++------------ 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/include/fplus/variant.hpp b/include/fplus/variant.hpp index 732ffa38..9e1dc45d 100644 --- a/include/fplus/variant.hpp +++ b/include/fplus/variant.hpp @@ -93,23 +93,20 @@ namespace internal { typedef std::shared_ptr type; }; - // http://stackoverflow.com/a/27588263/1866775 - - template - struct get_index; - - template - struct get_index : std::integral_constant { + template + struct contains { + /// True if T is in Ts... + constexpr static bool value = (std::is_same_v || ...); }; - template - struct get_index : std::integral_constant::value> { - }; - - template - struct get_index { - // condition is always false, but should be dependant of T - static_assert(sizeof(T) == 0, "element not found"); + template + struct get_index { + /// Index of type T in List. + constexpr static auto index = []() { + return (contains::value ? []() {signed i = 0; + (... && (!std::is_same_v && ++i)); + return i; }() : -1); + }(); }; template diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index 80894cdd..a71e5ab7 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -3295,7 +3295,7 @@ namespace internal { std::size_t pos_; }; -#if defined(_MSC_VER) && _MSC_VER >= 1900 +#if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 1915 template struct std::_Is_checked_helper> : public true_type { // mark array_back_insert_iterator as checked @@ -14329,23 +14329,20 @@ namespace internal { typedef std::shared_ptr type; }; - // http://stackoverflow.com/a/27588263/1866775 - - template - struct get_index; - template - struct get_index : std::integral_constant { - }; - - template - struct get_index : std::integral_constant::value> { - }; - - template - struct get_index { - // condition is always false, but should be dependant of T - static_assert(sizeof(T) == 0, "element not found"); + struct contains { + /// True if T is in Ts... + constexpr static bool value = (std::is_same_v || ...); + }; + + template + struct get_index { + /// Index of type T in List. + constexpr static auto index = []() { + return (contains::value ? []() {signed i = 0; + (... && (!std::is_same_v && ++i)); + return i; }() : -1); + }(); }; template From 6c478a234273565ad1f7889543bf0c67bbbc1be5 Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Sat, 14 Jun 2025 10:20:13 -0400 Subject: [PATCH 2/7] fixed get_index error --- CMakeLists.txt | 2 +- include/fplus/variant.hpp | 2 +- include_all_in_one/include/fplus/fplus.hpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d21a29a1..e2633a86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ target_include_directories( "$" ) -target_compile_features(fplus INTERFACE cxx_std_14) +target_compile_features(fplus INTERFACE cxx_std_23) find_package(Threads REQUIRED) target_link_libraries(fplus INTERFACE Threads::Threads) diff --git a/include/fplus/variant.hpp b/include/fplus/variant.hpp index 9e1dc45d..edfbd356 100644 --- a/include/fplus/variant.hpp +++ b/include/fplus/variant.hpp @@ -104,7 +104,7 @@ namespace internal { /// Index of type T in List. constexpr static auto index = []() { return (contains::value ? []() {signed i = 0; - (... && (!std::is_same_v && ++i)); + (... && (!std::is_same_v && ++i)); return i; }() : -1); }(); }; diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index a71e5ab7..4a411768 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -14329,10 +14329,10 @@ namespace internal { typedef std::shared_ptr type; }; - template + template struct contains { /// True if T is in Ts... - constexpr static bool value = (std::is_same_v || ...); + constexpr static bool value = (std::is_same_v || ...); }; template From 9edce489fb9563cd942f28703480d0ee8dd7374f Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Sun, 15 Jun 2025 23:17:30 -0400 Subject: [PATCH 3/7] testing local environment --- include/fplus/variant.hpp | 7 ++++--- include_all_in_one/include/fplus/fplus.hpp | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/fplus/variant.hpp b/include/fplus/variant.hpp index edfbd356..6e7f866f 100644 --- a/include/fplus/variant.hpp +++ b/include/fplus/variant.hpp @@ -102,10 +102,11 @@ namespace internal { template struct get_index { /// Index of type T in List. - constexpr static auto index = []() { - return (contains::value ? []() {signed i = 0; + static_assert(contains::value, "element is not in list"); + constexpr static auto value = []() { + return ([]() {std::size_t i = 0; (... && (!std::is_same_v && ++i)); - return i; }() : -1); + return i; }()); }(); }; diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index 4a411768..99a0b111 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -14338,10 +14338,11 @@ namespace internal { template struct get_index { /// Index of type T in List. - constexpr static auto index = []() { - return (contains::value ? []() {signed i = 0; - (... && (!std::is_same_v && ++i)); - return i; }() : -1); + static_assert(contains::value, "element is not in list"); + constexpr static auto value = []() { + return ([]() {std::size_t i = 0; + (... && (!std::is_same_v && ++i)); + return i; }()); }(); }; From 0bdf71f5688bb26513a9e44b562ca4d2f32f56a1 Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Mon, 16 Jun 2025 09:19:21 -0400 Subject: [PATCH 4/7] changed standard version to test CI --- CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2633a86..f7282a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ target_include_directories( "$" ) -target_compile_features(fplus INTERFACE cxx_std_23) +target_compile_features(fplus INTERFACE cxx_std_17) find_package(Threads REQUIRED) target_link_libraries(fplus INTERFACE Threads::Threads) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a10914a..316b46c8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -75,6 +75,6 @@ foreach (name IN LISTS tests) FunctionalPlus::fplus doctest::doctest ) - target_compile_features("${name}" PRIVATE cxx_std_14) + target_compile_features("${name}" PRIVATE cxx_std_17) doctest_discover_tests("${name}") endforeach () From 1ff0b33cb42d2ba5aaa626fa890d37904aa230d1 Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Mon, 16 Jun 2025 09:27:37 -0400 Subject: [PATCH 5/7] reverted test build cmake to 14 --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 316b46c8..0a10914a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -75,6 +75,6 @@ foreach (name IN LISTS tests) FunctionalPlus::fplus doctest::doctest ) - target_compile_features("${name}" PRIVATE cxx_std_17) + target_compile_features("${name}" PRIVATE cxx_std_14) doctest_discover_tests("${name}") endforeach () From 982899e2ff6aabbf8c9b4f9b9b24a37b02bf6ae4 Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:18:11 -0400 Subject: [PATCH 6/7] changed c++23 to 17 --- include/fplus/function_traits.hpp | 34 +++++++++++----------- include_all_in_one/include/fplus/fplus.hpp | 34 +++++++++++----------- test/CMakeLists.txt | 4 +-- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index 9598f748..3858ef2a 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -85,22 +85,6 @@ namespace utils { : public function_traits { }; - namespace xx_impl { - template - struct memfn_type { - typedef typename std::conditional< - std::is_const::value, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) const volatile, - R (C::*)(A...) const>::type, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) volatile, - R (C::*)(A...)>::type>::type type; - }; - } - template struct function_traits { /** @@ -145,6 +129,22 @@ namespace utils { }; }; + namespace xx_impl { + template + struct memfn_type { + typedef typename std::conditional< + std::is_const::value, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) const volatile, + R (C::*)(A...) const>::type, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) volatile, + R (C::*)(A...)>::type>::type type; + }; + } + #if __cplusplus > 201510L template @@ -441,7 +441,7 @@ namespace internal { }; template - struct has_function_traits : std::true_type { + struct has_function_traits : std::true_type { }; template diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index 99a0b111..bf290851 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -344,22 +344,6 @@ namespace utils { : public function_traits { }; - namespace xx_impl { - template - struct memfn_type { - typedef typename std::conditional< - std::is_const::value, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) const volatile, - R (C::*)(A...) const>::type, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) volatile, - R (C::*)(A...)>::type>::type type; - }; - } - template struct function_traits { /** @@ -404,6 +388,22 @@ namespace utils { }; }; + namespace xx_impl { + template + struct memfn_type { + typedef typename std::conditional< + std::is_const::value, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) const volatile, + R (C::*)(A...) const>::type, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) volatile, + R (C::*)(A...)>::type>::type type; + }; + } + #if __cplusplus > 201510L template @@ -700,7 +700,7 @@ namespace internal { }; template - struct has_function_traits : std::true_type { + struct has_function_traits : std::true_type { }; template diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a10914a..025344cf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,9 +15,7 @@ include(../cmake/warnings.cmake) find_package(doctest 2.4.11 CONFIG REQUIRED) # for doctest_discover_tests include(doctest) - enable_testing() - set( tests show_versions @@ -75,6 +73,6 @@ foreach (name IN LISTS tests) FunctionalPlus::fplus doctest::doctest ) - target_compile_features("${name}" PRIVATE cxx_std_14) + target_compile_features("${name}" PRIVATE cxx_std_17) doctest_discover_tests("${name}") endforeach () From 7ce200c165d8447b7cc4137b49b35a7bd5d7dbdf Mon Sep 17 00:00:00 2001 From: PraisePancakes <100659653+PraisePancakes@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:23:07 -0400 Subject: [PATCH 7/7] reverted xx_impl --- include/fplus/function_traits.hpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index 3858ef2a..9c0bac76 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -85,6 +85,21 @@ namespace utils { : public function_traits { }; + namespace xx_impl { + template + struct memfn_type { + typedef typename std::conditional< + std::is_const::value, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) const volatile, + R (C::*)(A...) const>::type, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) volatile, + R (C::*)(A...)>::type>::type type; + }; + } template struct function_traits { /** @@ -129,22 +144,6 @@ namespace utils { }; }; - namespace xx_impl { - template - struct memfn_type { - typedef typename std::conditional< - std::is_const::value, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) const volatile, - R (C::*)(A...) const>::type, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) volatile, - R (C::*)(A...)>::type>::type type; - }; - } - #if __cplusplus > 201510L template