avoid mystruct at begining of choosen testswith SFINAE technic
This commit is contained in:
6
Makefile
6
Makefile
@@ -38,9 +38,9 @@ CC = c++
|
|||||||
EXT = cpp
|
EXT = cpp
|
||||||
|
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||||
CFLAGS += -std=c++98
|
#CFLAGS += -std=c++98
|
||||||
CFLAGS += -MMD -MP #see end-page note on header dependencie
|
#CFLAGS += -MMD -MP #see end-page note on header dependencie
|
||||||
CFLAGS += -g3
|
#CFLAGS += -g3
|
||||||
|
|
||||||
CFLAGS_STL = $(CFLAGS)
|
CFLAGS_STL = $(CFLAGS)
|
||||||
CFLAGS_STL += -D STL
|
CFLAGS_STL += -D STL
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
# define TOI(n) toi<T>(n)
|
# define TOI(n) toi<T>(n)
|
||||||
# define PRINT(n) print<>(n, #n);
|
# define PRINT(n) print<>(n, #n);
|
||||||
# define DELETE delete_structs();
|
# define DELETE delete_structs();
|
||||||
# define DISALLOW_MYSTRUCT allow_mystruct = 0;
|
# define AVOID_MYSTRUCT(T) if (is_mystruct_type<T>::value) {return;}
|
||||||
|
|
||||||
|
|
||||||
// prototypes
|
// 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, "int", new(s_ ## f_name <int>));\
|
||||||
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
|
add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
|
||||||
add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
|
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*>));\
|
add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
|
||||||
allow_mystruct = 1;\
|
|
||||||
}\
|
}\
|
||||||
template <class T>\
|
template <class T>\
|
||||||
void s_ ## f_name <T>::func()
|
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, 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, 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, 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, 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, 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, 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>\
|
template <class T, class U>\
|
||||||
void s_ ## f_name <T, U>::func()
|
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
|
// 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 :
|
// specialization in header, make it inline :
|
||||||
// https://stackoverflow.com/questions/63529059/c-specialized-method-templates-produce-multiple-definition-errors
|
// https://stackoverflow.com/questions/63529059/c-specialized-method-templates-produce-multiple-definition-errors
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// global variables
|
|
||||||
// ****************************************
|
|
||||||
int allow_mystruct = 1;
|
|
||||||
|
|
||||||
|
|
||||||
// templates print
|
// templates print
|
||||||
// *****************************************
|
// *****************************************
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
@@ -658,6 +658,7 @@ TEST_M(tests_map_get_allocator)
|
|||||||
|
|
||||||
TEST_M(tests_map_relational_operators)
|
TEST_M(tests_map_relational_operators)
|
||||||
{
|
{
|
||||||
|
AVOID_MYSTRUCT(U)
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference)
|
TITLE(cplusplus.com reference)
|
||||||
|
|
||||||
|
|||||||
@@ -695,9 +695,9 @@ TEST_V(tests_vector_get_allocator)
|
|||||||
DELETE
|
DELETE
|
||||||
}
|
}
|
||||||
|
|
||||||
//DISALLOW_MYSTRUCT
|
|
||||||
TEST_V(tests_vector_relational_operators)
|
TEST_V(tests_vector_relational_operators)
|
||||||
{
|
{
|
||||||
|
AVOID_MYSTRUCT(T)
|
||||||
// title
|
// title
|
||||||
TITLE(cplusplus.com reference :)
|
TITLE(cplusplus.com reference :)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user