Skip to content

Commit

Permalink
Use __VA_ARGS__ in register macros
Browse files Browse the repository at this point in the history
See #141

Should work across all compilers we currently support, for any other
times when templated types are needed in a macro, just unroll the macro
manually and replace as necessary
  • Loading branch information
AzothAmmo committed Mar 1, 2016
1 parent 4c9286e commit 8db68d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
24 changes: 12 additions & 12 deletions include/cereal/details/polymorphic_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@
have been registered with CEREAL_REGISTER_ARCHIVE. This must be called
after all archives are registered (usually after the archives themselves
have been included). */
#define CEREAL_BIND_TO_ARCHIVES(T) \
namespace cereal { \
namespace detail { \
template<> \
struct init_binding<T> { \
static bind_to_archives<T> const & b; \
static void unused() { (void)b; } \
}; \
bind_to_archives<T> const & init_binding<T>::b = \
::cereal::detail::StaticObject< \
bind_to_archives<T> \
>::getInstance().bind(); \
#define CEREAL_BIND_TO_ARCHIVES(...) \
namespace cereal { \
namespace detail { \
template<> \
struct init_binding<__VA_ARGS__> { \
static bind_to_archives<__VA_ARGS__> const & b; \
static void unused() { (void)b; } \
}; \
bind_to_archives<__VA_ARGS__> const & init_binding<__VA_ARGS__>::b = \
::cereal::detail::StaticObject< \
bind_to_archives<__VA_ARGS__> \
>::getInstance().bind(); \
}} /* end namespaces */

namespace cereal
Expand Down
20 changes: 10 additions & 10 deletions include/cereal/types/polymorphic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@
Polymorphic support in cereal requires RTTI to be
enabled */
#define CEREAL_REGISTER_TYPE(T) \
namespace cereal { \
namespace detail { \
template <> \
struct binding_name<T> \
{ \
STATIC_CONSTEXPR char const * name() { return #T; } \
}; \
} } /* end namespaces */ \
CEREAL_BIND_TO_ARCHIVES(T)
#define CEREAL_REGISTER_TYPE(...) \
namespace cereal { \
namespace detail { \
template <> \
struct binding_name<__VA_ARGS__> \
{ \
STATIC_CONSTEXPR char const * name() { return #__VA_ARGS__; } \
}; \
} } /* end namespaces */ \
CEREAL_BIND_TO_ARCHIVES(__VA_ARGS__)

//! Registers a polymorphic type with cereal, giving it a
//! user defined name
Expand Down

0 comments on commit 8db68d2

Please sign in to comment.