27 #ifndef CEREAL_DETAILS_HELPERS_HPP_
28 #define CEREAL_DETAILS_HELPERS_HPP_
30 #include <type_traits>
37 class BinaryOutputArchive;
38 class BinaryInputArchive;
115 using DT =
typename std::decay<T>::type;
116 using Type =
typename std::conditional<std::is_rvalue_reference<T>::value,
118 typename std::add_lvalue_reference<DT>::type>::type;
120 static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value,
121 "Cannot pair a name to a NameValuePair" );
132 NameValuePair(
char const * n, T && v ) : name(n), value(const_cast<Type>(v)) {}
141 template<
class Archive,
class T>
inline
143 std::enable_if<std::is_same<Archive, ::cereal::BinaryInputArchive>::value ||
144 std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
146 make_nvp(
const char *, T && value )
148 return std::forward<T>(value);
154 template<
class Archive,
class T>
inline
156 std::enable_if<!std::is_same<Archive, ::cereal::BinaryInputArchive>::value &&
157 !std::is_same<Archive, ::cereal::BinaryOutputArchive>::value,
159 make_nvp(
const char * name, T && value)
161 return {name, std::forward<T>(value)};
168 #define _CEREAL_NVP(name, value) ::cereal::make_nvp<Archive>(name, value)
182 using PT =
typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value,
204 static const int32_t msb_32bit = 0x80000000;
205 static const int32_t msb2_32bit = 0x40000000;
223 using DT =
typename std::decay<T>::type;
224 using Type =
typename std::conditional<std::is_rvalue_reference<T>::value,
226 typename std::add_lvalue_reference<DT>::type>::type;
229 SizeTag( T && sz ) : size(const_cast<Type>(sz)) {}
255 template <
class Key,
class Value>
258 using DecayKey =
typename std::decay<Key>::type;
259 using KeyType =
typename std::conditional<
260 std::is_rvalue_reference<Key>::value,
262 typename std::add_lvalue_reference<DecayKey>::type>::type;
264 using DecayValue =
typename std::decay<Value>::type;
265 using ValueType =
typename std::conditional<
266 std::is_rvalue_reference<Value>::value,
268 typename std::add_lvalue_reference<DecayValue>::type>::type;
272 MapItem( Key && key, Value && value ) : key(const_cast<KeyType>(key)), value(const_cast<ValueType>(value)) {}
278 template <
class Archive>
inline
281 archive( make_nvp<Archive>(
"key", key),
282 make_nvp<Archive>(
"value", value) );
289 template <
class KeyType,
class ValueType>
inline
290 MapItem<KeyType, ValueType> make_map_item(KeyType && key, ValueType && value)
292 return {std::forward<KeyType>(key), std::forward<ValueType>(value)};
296 #endif // CEREAL_DETAILS_HELPERS_HPP_