2 \brief Support for types found in \<map\>
5 Copyright (c) 2014, Randolph Voorhies, Shane Grant
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 * Neither the name of cereal nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef CEREAL_TYPES_MAP_HPP_
31 #define CEREAL_TYPES_MAP_HPP_
33 #include <cereal/cereal.hpp>
41 template <class Archive, class MapT> inline
42 void save( Archive & ar, MapT const & map )
44 ar( make_size_tag( static_cast<size_type>(map.size()) ) );
46 for( const auto & i : map )
48 ar( make_map_item(i.first, i.second) );
53 template <class Archive, class MapT> inline
54 void load( Archive & ar, MapT & map )
57 ar( make_size_tag( size ) );
61 auto hint = map.begin();
62 for( size_t i = 0; i < size; ++i )
64 typename MapT::key_type key;
65 typename MapT::mapped_type value;
67 ar( make_map_item(key, value) );
68 #ifdef CEREAL_OLDER_GCC
69 hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) );
70 #else // NOT CEREAL_OLDER_GCC
71 hint = map.emplace_hint( hint, std::move( key ), std::move( value ) );
72 #endif // NOT CEREAL_OLDER_GCC
77 //! Saving for std::map
78 template <class Archive, class K, class T, class C, class A> inline
79 void save( Archive & ar, std::map<K, T, C, A> const & map )
81 map_detail::save( ar, map );
84 //! Loading for std::map
85 template <class Archive, class K, class T, class C, class A> inline
86 void load( Archive & ar, std::map<K, T, C, A> & map )
88 map_detail::load( ar, map );
91 //! Saving for std::multimap
92 /*! @note serialization for this type is not guaranteed to preserve ordering */
93 template <class Archive, class K, class T, class C, class A> inline
94 void save( Archive & ar, std::multimap<K, T, C, A> const & multimap )
96 map_detail::save( ar, multimap );
99 //! Loading for std::multimap
100 /*! @note serialization for this type is not guaranteed to preserve ordering */
101 template <class Archive, class K, class T, class C, class A> inline
102 void load( Archive & ar, std::multimap<K, T, C, A> & multimap )
104 map_detail::load( ar, multimap );
106 } // namespace cereal
108 #endif // CEREAL_TYPES_MAP_HPP_