TrinityCore
IteratorPair.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef IteratorPair_h__
19#define IteratorPair_h__
20
21#include <utility>
22
23namespace Trinity
24{
30 template<class iterator, class end_iterator = iterator>
32 {
33 public:
34 constexpr IteratorPair() : _iterators() { }
35 constexpr IteratorPair(iterator first, end_iterator second) : _iterators(first, second) { }
36 constexpr IteratorPair(std::pair<iterator, end_iterator> iterators) : _iterators(iterators) { }
37
38 constexpr iterator begin() const { return _iterators.first; }
39 constexpr end_iterator end() const { return _iterators.second; }
40
41 private:
42 std::pair<iterator, end_iterator> _iterators;
43 };
44
45 namespace Containers
46 {
47 template<typename iterator, class end_iterator = iterator>
48 constexpr IteratorPair<iterator, end_iterator> MakeIteratorPair(iterator first, end_iterator second)
49 {
50 return { first, second };
51 }
52
53 template<typename iterator, class end_iterator = iterator>
54 constexpr IteratorPair<iterator, end_iterator> MakeIteratorPair(std::pair<iterator, end_iterator> iterators)
55 {
56 return iterators;
57 }
58
59 template<class M>
60 auto MapEqualRange(M& map, typename M::key_type const& key)
61 {
62 return MakeIteratorPair(map.equal_range(key));
63 }
64 }
66}
68
69#endif // IteratorPair_h__
Utility class to enable range for loop syntax for multimap.equal_range uses.
Definition: IteratorPair.h:32
constexpr IteratorPair(std::pair< iterator, end_iterator > iterators)
Definition: IteratorPair.h:36
constexpr IteratorPair()
Definition: IteratorPair.h:34
constexpr IteratorPair(iterator first, end_iterator second)
Definition: IteratorPair.h:35
constexpr end_iterator end() const
Definition: IteratorPair.h:39
constexpr iterator begin() const
Definition: IteratorPair.h:38
std::pair< iterator, end_iterator > _iterators
Definition: IteratorPair.h:42
auto MapEqualRange(M &map, typename M::key_type const &key)
Definition: IteratorPair.h:60
constexpr IteratorPair< iterator, end_iterator > MakeIteratorPair(iterator first, end_iterator second)
Definition: IteratorPair.h:48