clang API Documentation

STLExtras.h
Go to the documentation of this file.
00001 //===--- STLExtras.h - Helper STL related templates -------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  Helper templates for using with the STL.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_INDEX_STLEXTRAS_H
00015 #define LLVM_CLANG_INDEX_STLEXTRAS_H
00016 
00017 namespace clang {
00018 
00019 namespace idx {
00020 
00021 /// \brief Wraps an iterator whose value_type is a pair, and provides
00022 /// pair's second object as the value.
00023 template <typename iter_type>
00024 class pair_value_iterator {
00025   iter_type I;
00026 
00027 public:
00028   typedef typename iter_type::value_type::second_type value_type;
00029   typedef value_type& reference;
00030   typedef value_type* pointer;
00031   typedef typename iter_type::iterator_category iterator_category;
00032   typedef typename iter_type::difference_type   difference_type;
00033 
00034   pair_value_iterator() { }
00035   pair_value_iterator(iter_type i) : I(i) { }
00036 
00037   reference operator*() const { return I->second; }
00038   pointer operator->() const { return &I->second; }
00039 
00040   pair_value_iterator& operator++() {
00041     ++I;
00042     return *this;
00043   }
00044 
00045   pair_value_iterator operator++(int) {
00046     pair_value_iterator tmp(*this);
00047     ++(*this);
00048     return tmp;
00049   }
00050 
00051   friend bool operator==(pair_value_iterator L, pair_value_iterator R) {
00052     return L.I == R.I;
00053   }
00054   friend bool operator!=(pair_value_iterator L, pair_value_iterator R) {
00055     return L.I != R.I;
00056   }
00057 };
00058 
00059 } // end idx namespace
00060 
00061 } // end clang namespace
00062 
00063 #endif