Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: src/base/adapters.h

Issue 1098863003: Import Reversed adapter from Chromium and use it in v8. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed feedback. Rebased. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | src/base/macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Slightly adapted for inclusion in V8.
6 // Copyright 2014 the V8 project authors. All rights reserved.
7
8 #ifndef V8_BASE_ADAPTERS_H_
9 #define V8_BASE_ADAPTERS_H_
10
11 #include "src/base/macros.h"
12
13 namespace v8 {
14 namespace base {
15
16 // Internal adapter class for implementing base::Reversed.
17 template <typename T>
18 class ReversedAdapter {
19 public:
20 typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator;
21
22 explicit ReversedAdapter(T& t) : t_(t) {}
23 ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {}
24
25 Iterator begin() const { return t_.rbegin(); }
26 Iterator end() const { return t_.rend(); }
27
28 private:
29 T& t_;
30
31 DISALLOW_ASSIGN(ReversedAdapter);
32 };
33
34 // Reversed returns a container adapter usable in a range-based "for" statement
35 // for iterating a reversible container in reverse order.
36 //
37 // Example:
38 //
39 // std::vector<int> v = ...;
40 // for (int i : base::Reversed(v)) {
41 // // iterates through v from back to front
42 // }
43 template <typename T>
44 ReversedAdapter<T> Reversed(T& t) {
45 return ReversedAdapter<T>(t);
46 }
47
48 } // namespace base
49 } // namespace v8
50
51 #endif // V8_BASE_ADAPTERS_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/base/macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698