LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
views.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <iterator>
12#include <boost/iterator/zip_iterator.hpp>
13#include <boost/range.hpp>
14
15namespace LC
16{
17namespace Util
18{
19namespace Views
20{
21 namespace detail
22 {
23 template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
24 using ValueType_t = PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type>;
25
26 template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
27 class PairIterator : public std::iterator<std::forward_iterator_tag, ValueType_t<PairType, FirstIt, SecondIt>>
28 {
29 bool IsSentinel_;
30
31 FirstIt First_;
32 FirstIt FirstEnd_;
33 SecondIt Second_;
34 SecondIt SecondEnd_;
35 public:
37 : IsSentinel_ { true }
38 {
39 }
40
41 PairIterator (const FirstIt& first, const FirstIt& firstEnd,
42 const SecondIt& second, const SecondIt& secondEnd)
43 : IsSentinel_ { false }
44 , First_ { first }
45 , FirstEnd_ { firstEnd }
46 , Second_ { second }
47 , SecondEnd_ { secondEnd }
48 {
49 }
50
51 bool operator== (const PairIterator& other) const
52 {
53 return (IsSentinel () && other.IsSentinel ()) ||
54 (First_ == other.First_ && Second_ == other.Second_);
55 }
56
57 bool operator!= (const PairIterator& other) const
58 {
59 return !(*this == other);
60 }
61
62 bool IsSentinel () const
63 {
64 return IsSentinel_ || First_ == FirstEnd_ || Second_ == SecondEnd_;
65 }
66
68 {
69 ++First_;
70 ++Second_;
71 return *this;
72 }
73
75 {
76 auto it = *this;
77
78 ++First_;
79 ++Second_;
80
81 return it;
82 }
83
84 PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type> operator* () const
85 {
86 return { *First_, *Second_ };
87 }
88 };
89
90 template<typename I1, typename I2, template<typename, typename> class PairType>
91 class ZipRange : public boost::iterator_range<PairIterator<PairType, I1, I2>>
92 {
94 public:
95 template<typename C1, typename C2>
96 ZipRange (C1&& c1, C2&& c2)
97 : boost::iterator_range<IteratorType_t>
98 {
99 IteratorType_t { c1.begin (), c1.end (), c2.begin (), c2.end () },
101 }
102 {
103 }
104 };
105 }
106
107 template<template<typename, typename> class PairType = QPair, typename C1, typename C2>
109 {
110 return { c1, c2 };
111 }
112}
113}
114}
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > operator*() const
Definition: views.h:84
bool operator==(const PairIterator &other) const
Definition: views.h:51
PairIterator(const FirstIt &first, const FirstIt &firstEnd, const SecondIt &second, const SecondIt &secondEnd)
Definition: views.h:41
bool operator!=(const PairIterator &other) const
Definition: views.h:57
ZipRange(C1 &&c1, C2 &&c2)
Definition: views.h:96
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > ValueType_t
Definition: views.h:24
detail::ZipRange< typename C1::const_iterator, typename C2::const_iterator, PairType > Zip(const C1 &c1, const C2 &c2)
Definition: views.h:108
Definition: constants.h:15
Definition: prelude.h:18