avoid mystruct at begining of choosen testswith SFINAE technic

This commit is contained in:
hugogogo
2022-07-04 15:50:26 +02:00
parent 52fa6ff65b
commit 581458ca37
5 changed files with 19 additions and 15 deletions

View File

@@ -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

View File

@@ -27,7 +27,7 @@
# define TOI(n) toi<T>(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<T>::value) {return;}
// prototypes
@@ -57,9 +57,7 @@ extern std::vector< mystruct* > mem_list;
add_to_list(#f_name, "int", new(s_ ## f_name <int>));\
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
if (allow_mystruct)\
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
allow_mystruct = 1;\
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
}\
template <class T>\
void s_ ## f_name <T>::func()
@@ -72,20 +70,30 @@ extern std::vector< mystruct* > mem_list;
add_to_list(#f_name, "char, int", new(s_ ## f_name <char, int>));\
add_to_list(#f_name, "char, char", new(s_ ## f_name <char, char>));\
add_to_list(#f_name, "char, std::string", new(s_ ## f_name <char, std::string>));\
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
add_to_list(#f_name, "int, char", new(s_ ## f_name <int, char>));\
add_to_list(#f_name, "int, std::string", new(s_ ## f_name <int, std::string>));\
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
}\
template <class T, class U>\
void s_ ## f_name <T, U>::func()
/*
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
*/
// templates get value
// *************************************
template <class T> struct is_mystruct_type
{
typedef char yes[1];
typedef yes no[2];
static T type;
static yes& test(mystruct*);
template <class C> 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 <class T>

View File

@@ -14,11 +14,6 @@
#endif
// global variables
// ****************************************
int allow_mystruct = 1;
// templates print
// *****************************************
template <class T>

View File

@@ -658,6 +658,7 @@ TEST_M(tests_map_get_allocator)
TEST_M(tests_map_relational_operators)
{
AVOID_MYSTRUCT(U)
// title
TITLE(cplusplus.com reference)

View File

@@ -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 :)