Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / tools / clang / rewrite_scoped_refptr / tests / test12-original.cc
blob33f1eb12ef14fec35eb29070b364043654e04a17
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.
5 #include <iterator>
6 #include <map>
7 #include <string>
9 #include "scoped_refptr.h"
11 struct Foo {
12 int dummy;
15 typedef std::map<std::string, scoped_refptr<const Foo> > MyMap;
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;
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_; }
31 private:
32 MyMap::const_iterator it_;
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 if (*it)
44 item = *it;