Commit 8148d03c authored by Dominik Charousset's avatar Dominik Charousset

Fix CAF_ADD_TYPE_ID on MSVC

parent fd02800e
......@@ -29,6 +29,10 @@
/// Evaluate x and y before concatenating into a single token.
#define CAF_PP_PASTE(x, y) CAF_PP_CAT(x, y)
/// Evaluates to __COUNTER__. Allows delaying evaluation of __COUNTER__ in some
/// edge cases where it otherwise could increment the internal counter twice.
#define CAF_PP_COUNTER() __COUNTER__
#ifdef CAF_MSVC
/// Computes the number of arguments of a variadic pack.
......
......@@ -98,28 +98,53 @@ constexpr type_id_t first_custom_type_id = 200;
constexpr type_id_t project_name##_first_type_id = first_id; \
}
#ifdef CAF_MSVC
/// Assigns the next free type ID to `fully_qualified_name`.
#define CAF_ADD_TYPE_ID(project_name, fully_qualified_name) \
namespace caf { \
template <> \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
= project_name##_first_type_id \
+ (__COUNTER__ - project_name##_type_id_counter_init - 1); \
}; \
template <> \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
using type = CAF_PP_EXPAND fully_qualified_name; \
}; \
template <> \
struct type_name<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr const char* value \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
}
# define CAF_ADD_TYPE_ID(project_name, fully_qualified_name) \
namespace caf { \
template <> \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
= project_name##_first_type_id \
+ (CAF_PP_CAT(CAF_PP_COUNTER, ()) \
- project_name##_type_id_counter_init - 1); \
}; \
template <> \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
using type = CAF_PP_EXPAND fully_qualified_name; \
}; \
template <> \
struct type_name<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr const char* value \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
}
#else
# define CAF_ADD_TYPE_ID(project_name, fully_qualified_name) \
namespace caf { \
template <> \
struct type_id<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr type_id_t value \
= project_name##_first_type_id \
+ (__COUNTER__ - project_name##_type_id_counter_init - 1); \
}; \
template <> \
struct type_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> { \
using type = CAF_PP_EXPAND fully_qualified_name; \
}; \
template <> \
struct type_name<CAF_PP_EXPAND fully_qualified_name> { \
static constexpr const char* value \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND fully_qualified_name>::value> \
: type_name<CAF_PP_EXPAND fully_qualified_name> {}; \
}
#endif
/// Creates a new tag type (atom) in the global namespace and assigns the next
/// free type ID to it.
......@@ -154,7 +179,7 @@ constexpr type_id_t first_custom_type_id = 200;
return f(caf::meta::type_name(#atom_namespace "::" #atom_name)); \
} \
} \
CAF_ADD_TYPE_ID(project_name, (atom_namespace ::atom_name))
CAF_ADD_TYPE_ID(project_name, (atom_namespace::atom_name))
#ifdef CAF_MSVC
# define CAF_ADD_ATOM(...) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment