OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This file contains adapters to iterate containers in alternative orders. | |
brettw
2014/09/29 16:55:14
I'd just remove this line. We could potentially ad
mdempsky
2014/09/29 17:47:40
Done.
| |
6 // | |
7 // Example: | |
8 // | |
9 // std::vector<int> v = ...; | |
10 // for (int i : base::reversed(v)) { | |
11 // // iterates through v in reverse order | |
12 // } | |
13 | |
14 #ifndef BASE_CONTAINERS_ADAPTERS_H_ | |
15 #define BASE_CONTAINERS_ADAPTERS_H_ | |
16 | |
17 #include "base/macros.h" | |
18 | |
19 namespace base { | |
20 | |
21 namespace internal { | |
22 | |
23 template <typename T> | |
brettw
2014/09/29 16:55:14
Can you include an example here?
mdempsky
2014/09/29 17:47:40
This class isn't intended for end users. I've adde
| |
24 class ReversedAdapter { | |
25 public: | |
26 typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator; | |
27 | |
28 explicit ReversedAdapter(T& t) : t_(t) {} | |
29 ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {} | |
30 | |
31 friend Iterator begin(const ReversedAdapter& ra) { return ra.t_.rbegin(); } | |
brettw
2014/09/29 16:55:14
I don't understand what "friend" does in this cont
mdempsky
2014/09/29 17:47:41
Turns out it's not necessary; I was looking at an
| |
32 friend Iterator end(const ReversedAdapter& ra) { return ra.t_.rend(); } | |
33 | |
34 private: | |
35 T& t_; | |
36 | |
37 DISALLOW_ASSIGN(ReversedAdapter); | |
38 }; | |
39 | |
40 } // namespace internal | |
41 | |
42 template <typename T> | |
43 internal::ReversedAdapter<T> reversed(T& t) { | |
brettw
2014/09/29 16:55:14
Google-style would say this should be capitalized.
mdempsky
2014/09/29 17:47:41
Done.
| |
44 return internal::ReversedAdapter<T>(t); | |
45 } | |
46 | |
47 } // namespace base | |
48 | |
49 #endif // BASE_CONTAINERS_ADAPTERS_H_ | |
OLD | NEW |