KeyValuePair.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Provides a pair of Key and Value, as well as functions working with them.
5  *
6  *
7  *
8  *
9  * \author Oswin Krause
10  * \date 2012
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 #ifndef SHARK_CORE_KEY_VALUE_PAIR_H
34 #define SHARK_CORE_KEY_VALUE_PAIR_H
35 
36 namespace shark{
37 
38 ///\brief Represents a Key-Value-Pair similar std::pair which is strictly ordered by it's key
39 ///
40 ///Key must be less-than comparable using operator<
41 template<class Key, class Value>
42 struct KeyValuePair{
43  Key key;
44  Value value;
45 
46  KeyValuePair():key(), value(){}
47  KeyValuePair(Key const& key, Value const& value)
48  :key(key),value(value){}
49 
50  template<class K, class V>
52  :key(pair.key),value(pair.value){}
53 
54  template<class K, class V>
55  bool operator==(KeyValuePair<K,V> const& pair) const{
56  return key == pair.key;
57  }
58  template<class K, class V>
59  bool operator!=(KeyValuePair<K,V> const& pair) const{
60  return key != pair.key;
61  }
62  template<class K, class V>
63  bool operator<(KeyValuePair<K,V> const& pair) const{
64  return key < pair.key;
65  }
66  template<class K, class V>
67  bool operator<=(KeyValuePair<K,V> const& pair) const{
68  return key <= pair.key;
69  }
70  template<class K, class V>
71  bool operator>(KeyValuePair<K,V> const& pair) const{
72  return key > pair.key;
73  }
74  template<class K, class V>
75  bool operator>=(KeyValuePair<K,V> const& pair) const{
76  return key >= pair.key;
77  }
78 
79  template<class Archive>
80  void serialize(Archive &ar, const unsigned int /*file_version*/) {
81  ar & key;
82  ar & value;
83  }
84 };
85 
86 ///\brief Swaps the contents of two instances of KeyValuePair
87 template<class K, class V>
89  using std::swap;
90  swap(pair1.key,pair2.key);
91  swap(pair1.value,pair2.value);
92 }
93 
94 ///\brief Creates a KeyValuePair
95 template<class Key, class Value>
98 }
99 
100 /// \endcond
101 
102 }
103 #endif