From 581458ca37a1714fde96790537cdeb74a759dddf Mon Sep 17 00:00:00 2001 From: hugogogo Date: Mon, 4 Jul 2022 15:50:26 +0200 Subject: [PATCH] avoid mystruct at begining of choosen testswith SFINAE technic --- Makefile | 6 +++--- tests/includes/tests_utils.hpp | 20 ++++++++++++++------ tests/includes/tests_vector.hpp | 5 ----- tests/tests_map.cpp | 1 + tests/tests_vector.cpp | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 219c2e5..6384635 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,9 @@ CC = c++ EXT = cpp CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -CFLAGS += -std=c++98 -CFLAGS += -MMD -MP #see end-page note on header dependencie -CFLAGS += -g3 +#CFLAGS += -std=c++98 +#CFLAGS += -MMD -MP #see end-page note on header dependencie +#CFLAGS += -g3 CFLAGS_STL = $(CFLAGS) CFLAGS_STL += -D STL diff --git a/tests/includes/tests_utils.hpp b/tests/includes/tests_utils.hpp index 314fb9c..a200cd6 100644 --- a/tests/includes/tests_utils.hpp +++ b/tests/includes/tests_utils.hpp @@ -27,7 +27,7 @@ # define TOI(n) toi(n) # define PRINT(n) print<>(n, #n); # define DELETE delete_structs(); -# define DISALLOW_MYSTRUCT allow_mystruct = 0; +# define AVOID_MYSTRUCT(T) if (is_mystruct_type::value) {return;} // prototypes @@ -57,9 +57,7 @@ extern std::vector< mystruct* > mem_list; add_to_list(#f_name, "int", new(s_ ## f_name ));\ add_to_list(#f_name, "char", new(s_ ## f_name ));\ add_to_list(#f_name, "std::string", new(s_ ## f_name ));\ - if (allow_mystruct)\ - add_to_list(#f_name, "mystruct*", new(s_ ## f_name ));\ - allow_mystruct = 1;\ + add_to_list(#f_name, "mystruct*", new(s_ ## f_name ));\ }\ template \ void s_ ## f_name ::func() @@ -72,20 +70,30 @@ extern std::vector< mystruct* > mem_list; add_to_list(#f_name, "char, int", new(s_ ## f_name ));\ add_to_list(#f_name, "char, char", new(s_ ## f_name ));\ add_to_list(#f_name, "char, std::string", new(s_ ## f_name ));\ + add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name ));\ add_to_list(#f_name, "int, int", new(s_ ## f_name ));\ add_to_list(#f_name, "int, char", new(s_ ## f_name ));\ add_to_list(#f_name, "int, std::string", new(s_ ## f_name ));\ + add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name ));\ }\ template \ void s_ ## f_name ::func() /* - add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name ));\ - add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name ));\ */ // templates get value // ************************************* +template struct is_mystruct_type +{ + typedef char yes[1]; + typedef yes no[2]; + static T type; + + static yes& test(mystruct*); + template static no& test(C); + static const bool value = sizeof(test(type)) == sizeof(yes); +}; // specialization in header, make it inline : // https://stackoverflow.com/questions/63529059/c-specialized-method-templates-produce-multiple-definition-errors template diff --git a/tests/includes/tests_vector.hpp b/tests/includes/tests_vector.hpp index 0888b99..5da7c7a 100644 --- a/tests/includes/tests_vector.hpp +++ b/tests/includes/tests_vector.hpp @@ -14,11 +14,6 @@ #endif -// global variables -// **************************************** -int allow_mystruct = 1; - - // templates print // ***************************************** template diff --git a/tests/tests_map.cpp b/tests/tests_map.cpp index 7a5a104..5ff2b04 100644 --- a/tests/tests_map.cpp +++ b/tests/tests_map.cpp @@ -658,6 +658,7 @@ TEST_M(tests_map_get_allocator) TEST_M(tests_map_relational_operators) { + AVOID_MYSTRUCT(U) // title TITLE(cplusplus.com reference) diff --git a/tests/tests_vector.cpp b/tests/tests_vector.cpp index d6e96a6..72ed431 100644 --- a/tests/tests_vector.cpp +++ b/tests/tests_vector.cpp @@ -695,9 +695,9 @@ TEST_V(tests_vector_get_allocator) DELETE } -//DISALLOW_MYSTRUCT TEST_V(tests_vector_relational_operators) { + AVOID_MYSTRUCT(T) // title TITLE(cplusplus.com reference :)