Don't preload rarely seen large images
[chromium-blink-merge.git] / base / containers / adapters.h
blobcc151fc2468bfd630f80e959437fe95fb2d3724b
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.
5 #ifndef BASE_CONTAINERS_ADAPTERS_H_
6 #define BASE_CONTAINERS_ADAPTERS_H_
8 #include "base/macros.h"
10 namespace base {
12 namespace internal {
14 // Internal adapter class for implementing base::Reversed.
15 template <typename T>
16 class ReversedAdapter {
17 public:
18 typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator;
20 explicit ReversedAdapter(T& t) : t_(t) {}
21 ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {}
23 Iterator begin() const { return t_.rbegin(); }
24 Iterator end() const { return t_.rend(); }
26 private:
27 T& t_;
29 DISALLOW_ASSIGN(ReversedAdapter);
32 } // namespace internal
34 // Reversed returns a container adapter usable in a range-based "for" statement
35 // for iterating a reversible container in reverse order.
37 // Example:
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 internal::ReversedAdapter<T> Reversed(T& t) {
45 return internal::ReversedAdapter<T>(t);
48 } // namespace base
50 #endif // BASE_CONTAINERS_ADAPTERS_H_