TrinityCore
Loading...
Searching...
No Matches
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 "Define.h"
22#include <utility>
23
24namespace Trinity
25{
31 template<class iterator, class end_iterator = iterator>
33 {
34 public:
35 constexpr IteratorPair() : _iterators() { }
36 constexpr IteratorPair(iterator first, end_iterator second) : _iterators(first, second) { }
37 constexpr IteratorPair(std::pair<iterator, end_iterator> iterators) : _iterators(iterators) { }
38
39 constexpr iterator begin() const { return _iterators.first; }
40 constexpr end_iterator end() const { return _iterators.second; }
41
42 private:
43 std::pair<iterator, end_iterator> _iterators;
44 };
45
46 namespace Containers
47 {
48 template<typename iterator, class end_iterator = iterator>
49 constexpr IteratorPair<iterator, end_iterator> MakeIteratorPair(iterator first, end_iterator second)
50 {
51 return { first, second };
52 }
53
54 template<typename iterator, class end_iterator = iterator>
55 constexpr IteratorPair<iterator, end_iterator> MakeIteratorPair(std::pair<iterator, end_iterator> iterators)
56 {
57 return iterators;
58 }
59
60 template<class M>
61 auto MapEqualRange(M& map, typename M::key_type const& key)
62 {
63 return MakeIteratorPair(map.equal_range(key));
64 }
65 }
67}
69
70#endif // IteratorPair_h__
Utility class to enable range for loop syntax for multimap.equal_range uses.
constexpr IteratorPair(std::pair< iterator, end_iterator > iterators)
constexpr IteratorPair()
constexpr IteratorPair(iterator first, end_iterator second)
constexpr end_iterator end() const
constexpr iterator begin() const
std::pair< iterator, end_iterator > _iterators
auto MapEqualRange(M &map, typename M::key_type const &key)
constexpr IteratorPair< iterator, end_iterator > MakeIteratorPair(iterator first, end_iterator second)