Feature #1444

General Implementation for Serializing Enums

Added by Nils Deppe over 2 years ago. Updated over 1 year ago.

Target version:
Start date:
Due date:
% Done:



Currently it's not possible to serialize enums in general. However, by using C++11's std::is_enum this can be done by as follows:

template <typename T,
          typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
inline void operator|(PUP::er& p, T& s) {
  pup_bytes(&p, static_cast<void*>(&s), sizeof(T));

This also requires modifying pup.h to

#if __cplusplus >= 201103L
namespace charm_pup_details {

template <typename... Ts>
struct make_void {
  typedef void type;
template <typename... Ts>
using void_t = typename make_void<Ts...>::type;

template <typename T, typename U = void>
struct is_pupable : std::false_type{};

template <typename T>
struct is_pupable<
    T, void_t<decltype(std::declval<T>().pup(std::declval<PUP::er &>()))>>
    : std::true_type {};

}  // namespace charm_pup_details
template <class T, typename std::enable_if<charm_pup_details::is_pupable<T>::value, int>::type = 0>
template <class T>
inline void operator|(PUP::er &p, T &t) {


#1 Updated by Sam White over 2 years ago

Thanks for pointing this out. After the release of Charm++ 6.8.0 (in the coming weeks), we will begin requiring full C++11 support. Before then, I don't think we want to add this because then depending on the compiler used to build Charm++ the application would need to specify their own PUP routine or not.

#2 Updated by Nils Deppe over 2 years ago

Yes, that makes sense. I'm really glad to hear full C++11 support will be required! We are currently using C++11 and some C++14 and have had to modify a couple other things in Charm++ to get it to work for us. I'm going to clean those changes up and submit feature requests with complete code there as well. Thanks for the quick response!

#3 Updated by Ronak Buch over 2 years ago

  • Target version set to 6.9.0

Thanks for your patch, Nils. If you'd like, you can directly submit it for code review and merge at As Sam said, it won't be included in the 6.8.0 release, but it's always good to get an early start on reviewing and testing patches.

If you have any questions about the patch submission process, feel free to contact me at .

#4 Updated by Eric Bohm over 1 year ago

  • Assignee set to Eric Mikida

#5 Updated by Eric Mikida over 1 year ago

  • Status changed from New to In Progress

#6 Updated by Eric Mikida over 1 year ago

Added a patch based on Nils code snippet:

#7 Updated by Eric Mikida over 1 year ago

  • Status changed from In Progress to Implemented

#8 Updated by Eric Mikida over 1 year ago

  • Status changed from Implemented to Merged

Also available in: Atom PDF