Unravel Engine C++ Reference
Loading...
Searching...
No Matches
pair_associative_container.hpp
Go to the documentation of this file.
1
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 ser20 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"
21 AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR
25 ANY
26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*/
33#ifndef SER20_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
34#define SER20_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
35
36#include "ser20/ser20.hpp"
37
38namespace ser20
39{
41template<class Archive,
42 template<typename...>
43 class Map,
44 typename... Args,
45 typename = typename Map<Args...>::mapped_type>
46inline void SER20_SAVE_FUNCTION_NAME(Archive& ar, Map<Args...> const& map)
47{
48 ar(make_size_tag(static_cast<size_type>(map.size())));
49
50 for(const auto& i : map)
51 ar(make_map_item(i.first, i.second));
52}
53
55template<class Archive,
56 template<typename...>
57 class Map,
58 typename... Args,
59 typename = typename Map<Args...>::mapped_type>
60inline void SER20_LOAD_FUNCTION_NAME(Archive& ar, Map<Args...>& map)
61{
62 size_type size;
63 ar(make_size_tag(size));
64
65 map.clear();
66
67 auto hint = map.begin();
68 for(size_t i = 0; i < size; ++i)
69 {
70 typename Map<Args...>::key_type key;
71 typename Map<Args...>::mapped_type value;
72
73 ar(make_map_item(key, value));
74#ifdef SER20_OLDER_GCC
75 hint = map.insert(hint, std::make_pair(std::move(key), std::move(value)));
76#else // NOT SER20_OLDER_GCC
77 hint = map.emplace_hint(hint, std::move(key), std::move(value));
78#endif // NOT SER20_OLDER_GCC
79 }
80}
81} // namespace ser20
82
83#endif // SER20_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_
Definition yaml.hpp:46
void SER20_LOAD_FUNCTION_NAME(YAMLInputArchive &ar, NameValuePair< T > &t)
Definition yaml.hpp:957
void SER20_SAVE_FUNCTION_NAME(YAMLOutputArchive &ar, NameValuePair< T > const &t)
Serializing NVP types to YAML.
Definition yaml.hpp:950