Line data Source code
1 : /*! \file pair_associative_container.hpp
2 : \brief Support for the PairAssociativeContainer refinement of the
3 : AssociativeContainer concept.
4 : \ingroup TypeConcepts */
5 : /*
6 : Copyright (c) 2014, Randolph Voorhies, Shane Grant
7 : All rights reserved.
8 :
9 : Redistribution and use in source and binary forms, with or without
10 : modification, are permitted provided that the following conditions are met:
11 : * Redistributions of source code must retain the above copyright
12 : notice, this list of conditions and the following disclaimer.
13 : * Redistributions in binary form must reproduce the above copyright
14 : notice, this list of conditions and the following disclaimer in the
15 : documentation and/or other materials provided with the distribution.
16 : * Neither the name of cereal nor the
17 : names of its contributors may be used to endorse or promote products
18 : derived from this software without specific prior written permission.
19 :
20 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 : ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 : WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 : DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
24 : DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 : (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 : LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 : ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 : (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 : SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 : */
31 : #ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
32 : #define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
33 :
34 : #include "cereal/cereal.hpp"
35 :
36 : namespace cereal
37 : {
38 : //! Saving for std-like pair associative containers
39 : template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
40 18400 : void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map<Args...> const & map )
41 : {
42 18400 : ar( make_size_tag( static_cast<size_type>(map.size()) ) );
43 :
44 2558894 : for( const auto & i : map )
45 2540494 : ar( make_map_item(i.first, i.second) );
46 18400 : }
47 800 :
48 : //! Loading for std-like pair associative containers
49 800 : template <class Archive, template <typename...> class Map, typename... Args, typename = typename Map<Args...>::mapped_type> inline
50 : void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map<Args...> & map )
51 117381 : {
52 116581 : size_type size;
53 800 : ar( make_size_tag( size ) );
54 800 :
55 : map.clear();
56 800 :
57 : auto hint = map.begin();
58 102800 : for( size_t i = 0; i < size; ++i )
59 102000 : {
60 800 : typename Map<Args...>::key_type key;
61 800 : typename Map<Args...>::mapped_type value;
62 :
63 800 : ar( make_map_item(key, value) );
64 : #ifdef CEREAL_OLDER_GCC
65 120786 : hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) );
66 119986 : #else // NOT CEREAL_OLDER_GCC
67 800 : hint = map.emplace_hint( hint, std::move( key ), std::move( value ) );
68 800 : #endif // NOT CEREAL_OLDER_GCC
69 : }
70 800 : }
71 : } // namespace cereal
72 120783 :
73 119983 : #endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
|