OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 #include <iterator> |
| 6 #include <map> |
| 7 #include <string> |
| 8 |
| 9 #include "scoped_refptr.h" |
| 10 |
| 11 struct Foo { |
| 12 int dummy; |
| 13 }; |
| 14 |
| 15 typedef std::map<std::string, scoped_refptr<const Foo> > MyMap; |
| 16 |
| 17 class MyIter |
| 18 : public std::iterator<std::input_iterator_tag, scoped_refptr<const Foo> > { |
| 19 public: |
| 20 MyIter() {} |
| 21 MyIter(const MyIter& other) : it_(other.it_) {} |
| 22 explicit MyIter(MyMap::const_iterator it) : it_(it) {} |
| 23 MyIter& operator++() { |
| 24 ++it_; |
| 25 return *this; |
| 26 } |
| 27 const scoped_refptr<const Foo> operator*() { return it_->second; } |
| 28 bool operator!=(const MyIter& other) { return it_ != other.it_; } |
| 29 bool operator==(const MyIter& other) { return it_ == other.it_; } |
| 30 |
| 31 private: |
| 32 MyMap::const_iterator it_; |
| 33 }; |
| 34 |
| 35 void TestsAScopedRefptr() { |
| 36 MyMap map; |
| 37 map["foo"] = new Foo; |
| 38 map["bar"] = new Foo; |
| 39 MyIter my_begin(map.begin()); |
| 40 MyIter my_end(map.end()); |
| 41 for (MyIter it = my_begin; it != my_end; ++it) { |
| 42 const Foo* item = NULL; |
| 43 item = it->get(); |
| 44 } |
| 45 } |
OLD | NEW |