1 From 17300ee96e42f8848d27db6fc97f04de293662d8 Mon Sep 17 00:00:00 2001
2 From: Erich Keane <erich.keane@intel.com>
3 Date: Thu, 6 Nov 2014 14:37:00 -0800
4 Subject: [PATCH] Get this to work on g++4.6.3
7 include/cereal/cereal.hpp | 2 +-
8 include/cereal/details/helpers.hpp | 32 ++++++++--------
9 include/cereal/details/traits.hpp | 61 +++++++++++++++++-------------
10 include/cereal/external/rapidjson/reader.h | 13 ++-----
11 include/cereal/external/rapidjson/writer.h | 12 ++----
12 include/cereal/types/common.hpp | 19 +++++++---
13 include/cereal/types/memory.hpp | 10 ++---
14 7 files changed, 77 insertions(+), 72 deletions(-)
16 diff --git a/include/cereal/cereal.hpp b/include/cereal/cereal.hpp
17 index b2858af..a219729 100644
18 --- a/include/cereal/cereal.hpp
19 +++ b/include/cereal/cereal.hpp
20 @@ -856,7 +856,7 @@ namespace cereal
21 std::uint32_t version;
23 process( make_nvp<ArchiveType>("cereal_class_version", version) );
24 - itsVersionedTypes.emplace_hint( lookupResult, hash, version );
25 + itsVersionedTypes.insert( lookupResult, std::pair<std::size_t, std::uint32_t>(hash, version) );
29 diff --git a/include/cereal/details/helpers.hpp b/include/cereal/details/helpers.hpp
30 index e792d44..60e13c8 100644
31 --- a/include/cereal/details/helpers.hpp
32 +++ b/include/cereal/details/helpers.hpp
33 @@ -55,7 +55,7 @@ namespace cereal
34 /*! To ensure compatability between 32, 64, etc bit machines, we need to use
35 * a fixed size type instead of size_t, which may vary from machine to
37 - using size_type = uint64_t;
38 + typedef uint64_t size_type;
41 class BinaryOutputArchive;
42 @@ -138,12 +138,12 @@ namespace cereal
43 // otherwise, we store a reference. If we were passed an array, don't
44 // decay the type - keep it as an array, and then proceed as normal
45 // with the RValue business
46 - using DT = typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
47 + typedef typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
48 typename std::remove_cv<T>::type,
49 - typename std::decay<T>::type>::type;
50 - using Type = typename std::conditional<std::is_rvalue_reference<T>::value,
51 + typename std::decay<T>::type>::type DT;
52 + typedef typename std::conditional<std::is_rvalue_reference<T>::value,
54 - typename std::add_lvalue_reference<DT>::type>::type;
55 + typename std::add_lvalue_reference<DT>::type>::type Type;
56 // prevent nested nvps
57 static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value,
58 "Cannot pair a name to a NameValuePair" );
59 @@ -207,9 +207,9 @@ namespace cereal
61 //! Internally store the pointer as a void *, keeping const if created with
63 - using PT = typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value,
64 + typedef typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value,
69 BinaryData( T && d, uint64_t s ) : data(d), size(s) {}
71 @@ -248,10 +248,10 @@ namespace cereal
73 // If we get passed an RValue, we'll just make a local copy if it here
74 // otherwise, we store a reference
75 - using DT = typename std::decay<T>::type;
76 - using Type = typename std::conditional<std::is_rvalue_reference<T>::value,
77 + typedef typename std::decay<T>::type DT;
78 + typedef typename std::conditional<std::is_rvalue_reference<T>::value,
80 - typename std::add_lvalue_reference<DT>::type>::type;
81 + typename std::add_lvalue_reference<DT>::type>::type Type;
84 SizeTag( T && sz ) : size(const_cast<Type>(sz)) {}
85 @@ -283,17 +283,17 @@ namespace cereal
86 template <class Key, class Value>
89 - using DecayKey = typename std::decay<Key>::type;
90 - using KeyType = typename std::conditional<
91 + typedef typename std::decay<Key>::type DecayKey;
92 + typedef typename std::conditional<
93 std::is_rvalue_reference<Key>::value,
95 - typename std::add_lvalue_reference<DecayKey>::type>::type;
96 + typename std::add_lvalue_reference<DecayKey>::type>::type KeyType;
98 - using DecayValue = typename std::decay<Value>::type;
99 - using ValueType = typename std::conditional<
100 + typedef typename std::decay<Value>::type DecayValue;
101 + typedef typename std::conditional<
102 std::is_rvalue_reference<Value>::value,
104 - typename std::add_lvalue_reference<DecayValue>::type>::type;
105 + typename std::add_lvalue_reference<DecayValue>::type>::type ValueType;
107 //! Construct a MapItem from a key and a value
109 diff --git a/include/cereal/details/traits.hpp b/include/cereal/details/traits.hpp
110 index 871886f..011054b 100644
111 --- a/include/cereal/details/traits.hpp
112 +++ b/include/cereal/details/traits.hpp
113 @@ -411,12 +411,12 @@ namespace cereal
116 template <class T, class A, bool Valid>
117 - struct get_member_save_minimal_type { using type = void; };
118 + struct get_member_save_minimal_type { typedef void type; };
120 template <class T, class A>
121 struct get_member_save_minimal_type<T, A, true>
123 - using type = decltype( cereal::access::member_save_minimal( std::declval<A const &>(), std::declval<T const &>() ) );
124 + typedef decltype( cereal::access::member_save_minimal( std::declval<A const &>(), std::declval<T const &>() ) ) type;
126 } // end namespace detail
128 @@ -428,7 +428,7 @@ namespace cereal
129 "cereal detected a non-const member save_minimal. "
130 "save_minimal member functions must always be const" );
132 - using type = typename detail::get_member_save_minimal_type<T, A, check::value>::type;
133 + typedef typename detail::get_member_save_minimal_type<T, A, check::value>::type type;
134 static_assert( (check::value && is_minimal_type<type>::value) || !check::value,
135 "cereal detected a member save_minimal with an invalid return type. "
136 "return type must be arithmetic or string" );
137 @@ -473,12 +473,12 @@ namespace cereal
140 template <class T, class A, bool Valid>
141 - struct get_member_versioned_save_minimal_type { using type = void; };
142 + struct get_member_versioned_save_minimal_type { typedef void type; };
144 template <class T, class A>
145 struct get_member_versioned_save_minimal_type<T, A, true>
147 - using type = decltype( cereal::access::member_save_minimal( std::declval<A const &>(), std::declval<T const &>(), 0 ) );
148 + typedef decltype( cereal::access::member_save_minimal( std::declval<A const &>(), std::declval<T const &>(), 0 ) ) type;
150 } // end namespace detail
152 @@ -490,7 +490,7 @@ namespace cereal
153 "cereal detected a versioned non-const member save_minimal. "
154 "save_minimal member functions must always be const" );
156 - using type = typename detail::get_member_versioned_save_minimal_type<T, A, check::value>::type;
157 + typedef typename detail::get_member_versioned_save_minimal_type<T, A, check::value>::type type;
158 static_assert( (check::value && is_minimal_type<type>::value) || !check::value,
159 "cereal detected a versioned member save_minimal with an invalid return type. "
160 "return type must be arithmetic or string" );
161 @@ -519,12 +519,12 @@ namespace cereal
164 template <class T, class A, bool Valid>
165 - struct get_non_member_save_minimal_type { using type = void; };
166 + struct get_non_member_save_minimal_type { typedef void type; };
168 template <class T, class A>
169 struct get_non_member_save_minimal_type <T, A, true>
171 - using type = decltype( save_minimal( std::declval<A const &>(), std::declval<T const &>() ) );
172 + typedef decltype( save_minimal( std::declval<A const &>(), std::declval<T const &>() ) ) type;
174 } // end namespace detail
176 @@ -536,7 +536,7 @@ namespace cereal
177 "cereal detected a non-const type parameter in non-member save_minimal. "
178 "save_minimal non-member functions must always pass their types as const" );
180 - using type = typename detail::get_non_member_save_minimal_type<T, A, check::value>::type;
181 + typedef typename detail::get_non_member_save_minimal_type<T, A, check::value>::type type;
182 static_assert( (check::value && is_minimal_type<type>::value) || !check::value,
183 "cereal detected a non-member save_minimal with an invalid return type. "
184 "return type must be arithmetic or string" );
185 @@ -565,12 +565,12 @@ namespace cereal
188 template <class T, class A, bool Valid>
189 - struct get_non_member_versioned_save_minimal_type { using type = void; };
190 + struct get_non_member_versioned_save_minimal_type { typedef void type; };
192 template <class T, class A>
193 struct get_non_member_versioned_save_minimal_type <T, A, true>
195 - using type = decltype( save_minimal( std::declval<A const &>(), std::declval<T const &>(), 0 ) );
196 + typedef decltype( save_minimal( std::declval<A const &>(), std::declval<T const &>(), 0 ) ) type;
198 } // end namespace detail
200 @@ -582,7 +582,7 @@ namespace cereal
201 "cereal detected a non-const type parameter in versioned non-member save_minimal. "
202 "save_minimal non-member functions must always pass their types as const" );
204 - using type = typename detail::get_non_member_versioned_save_minimal_type<T, A, check::value>::type;
205 + typedef typename detail::get_non_member_versioned_save_minimal_type<T, A, check::value>::type type;
206 static_assert( (check::value && is_minimal_type<type>::value) || !check::value,
207 "cereal detected a non-member versioned save_minimal with an invalid return type. "
208 "return type must be arithmetic or string" );
209 @@ -608,7 +608,7 @@ namespace cereal
210 template <class Source>
211 struct NoConvertConstRef : NoConvertBase
213 - using type = Source; //!< Used to get underlying type easily
214 + typedef Source type; //!< Used to get underlying type easily
216 template <class Dest, class = typename std::enable_if<std::is_same<Source, Dest>::value>::type>
217 operator Dest () = delete;
218 @@ -626,7 +626,7 @@ namespace cereal
219 template <class Source>
220 struct NoConvertRef : NoConvertBase
222 - using type = Source; //!< Used to get underlying type easily
223 + typedef Source type; //!< Used to get underlying type easily
225 template <class Dest, class = typename std::enable_if<std::is_same<Source, Dest>::value>::type>
226 operator Dest () = delete;
227 @@ -698,7 +698,7 @@ namespace cereal
228 "cereal detected member load_minimal but no valid member save_minimal. "
229 "cannot evaluate correctness of load_minimal without valid save_minimal." );
231 - using SaveType = typename detail::get_member_save_minimal_type<T, A, true>::type;
232 + typedef typename detail::get_member_save_minimal_type<T, A, true>::type SaveType;
233 const static bool value = has_member_load_minimal_impl<T, A>::value;
234 const static bool valid = has_member_load_minimal_type_impl<T, A, SaveType>::value;
236 @@ -759,7 +759,7 @@ namespace cereal
237 "cereal detected member versioned load_minimal but no valid member versioned save_minimal. "
238 "cannot evaluate correctness of load_minimal without valid save_minimal." );
240 - using SaveType = typename detail::get_member_versioned_save_minimal_type<T, A, true>::type;
241 + typedef typename detail::get_member_versioned_save_minimal_type<T, A, true>::type SaveType;
242 const static bool value = has_member_versioned_load_minimal_impl<T, A>::value;
243 const static bool valid = has_member_versioned_load_minimal_type_impl<T, A, SaveType>::value;
245 @@ -814,8 +814,8 @@ namespace cereal
246 "cereal detected non-member load_minimal but no valid non-member save_minimal. "
247 "cannot evaluate correctness of load_minimal without valid save_minimal." );
249 - using SaveType = typename detail::get_non_member_save_minimal_type<T, A, true>::type;
250 - using check = has_non_member_load_minimal_impl<T, A, SaveType>;
251 + typedef typename detail::get_non_member_save_minimal_type<T, A, true>::type SaveType;
252 + typedef has_non_member_load_minimal_impl<T, A, SaveType> check;
253 static const bool value = check::exists;
255 static_assert( check::valid || !check::exists, "cereal detected different types in corresponding non-member load_minimal and save_minimal functions. "
256 @@ -866,8 +866,8 @@ namespace cereal
257 "cereal detected non-member versioned load_minimal but no valid non-member versioned save_minimal. "
258 "cannot evaluate correctness of load_minimal without valid save_minimal." );
260 - using SaveType = typename detail::get_non_member_versioned_save_minimal_type<T, A, true>::type;
261 - using check = has_non_member_versioned_load_minimal_impl<T, A, SaveType>;
262 + typedef typename detail::get_non_member_versioned_save_minimal_type<T, A, true>::type SaveType;
263 + typedef has_non_member_versioned_load_minimal_impl<T, A, SaveType> check;;
264 static const bool value = check::exists;
266 static_assert( check::valid || !check::exists, "cereal detected different types in corresponding non-member versioned load_minimal and save_minimal functions. "
267 @@ -1182,9 +1182,16 @@ namespace cereal
271 + // works around the lack of decltype inheritance in GCC 4.6
273 + struct shared_wrapper
275 + typedef decltype(detail::shared_from_this_wrapper::check(std::declval<T>())) type;
278 //! Determine if T or any base class of T has inherited from std::enable_shared_from_this
280 - struct has_shared_from_this : decltype(detail::shared_from_this_wrapper::check(std::declval<T>()))
281 + struct has_shared_from_this : shared_wrapper<T>::type
284 //! Get the type of the base class of T which inherited from std::enable_shared_from_this
285 @@ -1192,10 +1199,10 @@ namespace cereal
286 struct get_shared_from_this_base
289 - using PtrType = decltype(detail::shared_from_this_wrapper::get(std::declval<T>()));
290 + typedef decltype(detail::shared_from_this_wrapper::get(std::declval<T>())) PtrType;
292 //! The type of the base of T that inherited from std::enable_shared_from_this
293 - using type = typename std::decay<typename PtrType::element_type>::type;
294 + typedef typename std::decay<typename PtrType::element_type>::type type;
297 // ######################################################################
298 @@ -1209,14 +1216,14 @@ namespace cereal
299 template <class T, bool IsCerealMinimalTrait = std::is_base_of<detail::NoConvertBase, T>::value>
306 //! Specialization for types wrapped in a NoConvert
308 struct strip_minimal<T, true>
310 - using type = typename T::type;
311 + typedef typename T::type type;
313 } // namespace traits
315 @@ -1232,10 +1239,12 @@ namespace cereal
320 + struct is_default_constructible : std::is_constructible<T>{};
321 template <class T, class A>
322 struct Construct<T, A, false, false>
324 - static_assert( std::is_default_constructible<T>::value,
325 + static_assert( is_default_constructible<T>::value,
326 "Trying to serialize a an object with no default constructor. \n\n "
327 "Types must either be default constructible or define either a member or non member Construct function. \n "
328 "Construct functions generally have the signature: \n\n "
329 diff --git a/include/cereal/external/rapidjson/reader.h b/include/cereal/external/rapidjson/reader.h
330 index 7790907..3ee838c 100644
331 --- a/include/cereal/external/rapidjson/reader.h
332 +++ b/include/cereal/external/rapidjson/reader.h
333 @@ -402,20 +402,13 @@ private:
336 // cereal Temporary until constexpr support is added in RTM
340 bool characterOk( Ch c )
346 - bool characterOk<char>( Ch )
353 // As part of a fix for GCC 4.7
355 static constexpr int to_int( T t ){ return t; }
356 @@ -432,7 +425,7 @@ private:
362 // Parse string, handling the prefix and suffix double quotes and escaping.
363 template<unsigned parseFlags, typename Stream, typename Handler>
364 void ParseString(Stream& stream, Handler& handler) {
365 diff --git a/include/cereal/external/rapidjson/writer.h b/include/cereal/external/rapidjson/writer.h
366 index 0f87255..e02c27a 100644
367 --- a/include/cereal/external/rapidjson/writer.h
368 +++ b/include/cereal/external/rapidjson/writer.h
369 @@ -177,20 +177,14 @@ protected:
372 // cereal Temporary until constexpr support is added in RTM
376 bool characterOk( Ch c )
382 - bool characterOk<char>( Ch )
389 // As part of a fix for GCC 4.7
391 static constexpr int to_int( T t ){ return t; }
392 @@ -206,7 +200,7 @@ protected:
393 typename std::enable_if< to_int(std::numeric_limits<Ch>::max()) >= to_int(256), bool>::type
399 //! \todo Optimization with custom double-to-string converter.
400 void WriteDouble(double d) {
401 diff --git a/include/cereal/types/common.hpp b/include/cereal/types/common.hpp
402 index abb8bfd..5c014cd 100644
403 --- a/include/cereal/types/common.hpp
404 +++ b/include/cereal/types/common.hpp
405 @@ -55,6 +55,15 @@ namespace cereal
410 + struct underlying_type
412 + typedef typename std::conditional<
414 + typename std::make_signed<en>::type,
415 + typename std::make_unsigned<en>::type
418 //! Gets the underlying type of an enum
420 template <class T, bool IsEnum>
421 @@ -64,7 +73,7 @@ namespace cereal
422 /*! Specialization for when we actually have an enum
425 - struct enum_underlying_type<T, true> { using type = typename std::underlying_type<T>::type; };
426 + struct enum_underlying_type<T, true> { typedef typename underlying_type<T>::type type; };
429 //! Checks if a type is an enum
430 @@ -78,13 +87,13 @@ namespace cereal
434 - using DecayedT = typename std::decay<T>::type;
435 - using StrippedT = typename ::cereal::traits::strip_minimal<DecayedT>::type;
436 + typedef typename std::decay<T>::type DecayedT;
437 + typedef typename ::cereal::traits::strip_minimal<DecayedT>::type StrippedT;
440 static const bool value = std::is_enum<StrippedT>::value;
441 - using type = StrippedT;
442 - using base_type = typename enum_underlying_type<StrippedT, value>::type;
443 + typedef StrippedT type;
444 + typedef typename enum_underlying_type<StrippedT, value>::type base_type;
448 diff --git a/include/cereal/types/memory.hpp b/include/cereal/types/memory.hpp
449 index bf56c92..d2357ff 100644
450 --- a/include/cereal/types/memory.hpp
451 +++ b/include/cereal/types/memory.hpp
452 @@ -115,9 +115,9 @@ namespace cereal
453 class EnableSharedStateHelper
455 // typedefs for parent type and storage type
456 - using BaseType = typename ::cereal::traits::get_shared_from_this_base<T>::type;
457 - using ParentType = std::enable_shared_from_this<BaseType>;
458 - using StorageType = typename std::aligned_storage<sizeof(ParentType)>::type;
459 + typedef typename ::cereal::traits::get_shared_from_this_base<T>::type BaseType;
460 + typedef std::enable_shared_from_this<BaseType> ParentType;
461 + typedef typename std::aligned_storage<sizeof(ParentType)>::type StorageType;
464 //! Saves the state of some type inheriting from enable_shared_from_this
465 @@ -257,7 +257,7 @@ namespace cereal
467 // Storage type for the pointer - since we can't default construct this type,
468 // we'll allocate it using std::aligned_storage and use a custom deleter
469 - using ST = typename std::aligned_storage<sizeof(T)>::type;
470 + typedef typename std::aligned_storage<sizeof(T)>::type ST;
472 // Valid flag - set to true once construction finishes
473 // This prevents us from calling the destructor on
474 @@ -345,7 +345,7 @@ namespace cereal
476 // Storage type for the pointer - since we can't default construct this type,
477 // we'll allocate it using std::aligned_storage
478 - using ST = typename std::aligned_storage<sizeof(T)>::type;
479 + typedef typename std::aligned_storage<sizeof(T)>::type ST;
481 // Allocate storage - note the ST type so that deleter is correct if
482 // an exception is thrown before we are initialized