LeechCraft 0.6.70-17609-g3dde4097dd
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
12{
13 namespace detail
14 {
15 template<template<typename, typename> class PairType, typename I1, typename I2>
17 {
18 I1 It1_;
19 const I1 It1End_;
20 I2 It2_;
21 const I2 It2End_;
22
23 bool operator== (const ZipIterator& other) const
24 {
25 if (IsSentinel () || other.IsSentinel ())
26 return IsSentinel () == other.IsSentinel ();
27
28 return It1_ == other.It1_ && It2_ == other.It2_;
29 }
30
31 bool IsSentinel () const
32 {
33 return It1_ == It1End_ || It2_ == It2End_;
34 }
35
37 {
38 ++It1_;
39 ++It2_;
40 return *this;
41 }
42
43 auto& operator++ (int)
44 {
45 auto it = *this;
46
47 ++It1_;
48 ++It2_;
49
50 return it;
51 }
52
53 auto operator* () const
54 {
55 return PairType { *It1_, *It2_ };
56 }
57 };
58 }
59
60 template<template<typename, typename> class PairType = QPair, typename C1, typename C2>
61 auto Zip (C1&& c1, C2&& c2)
62 {
63 using ZIt = detail::ZipIterator<PairType, typename std::decay_t<C1>::const_iterator, typename std::decay_t<C2>::const_iterator>;
64 struct Range
65 {
66 C1 C1_;
67 C2 C2_;
68
69 auto begin () const { return ZIt { C1_.cbegin (), C1_.cend (), C2_.cbegin (), C2_.cend () }; }
70 auto end () const { return ZIt { C1_.cend (), C1_.cend (), C2_.cend (), C2_.cend () }; }
71 };
72
73 return Range { std::forward<C1> (c1), std::forward<C2> (c2) };
74 }
75}
auto Zip(C1 &&c1, C2 &&c2)
Definition views.h:61
bool operator==(const ZipIterator &other) const
Definition views.h:23