yat
0.8.3pre
|
00001 #ifndef _theplu_yat_utility_weight_iterator_ 00002 #define _theplu_yat_utility_weight_iterator_ 00003 00004 // $Id: WeightIterator.h 2282 2010-06-26 01:38:17Z peter $ 00005 00006 /* 00007 Copyright (C) 2008 Jari Häkkinen, Peter Johansson 00008 Copyright (C) 2009, 2010 Peter Johansson 00009 00010 This file is part of the yat library, http://dev.thep.lu.se/yat 00011 00012 The yat library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU General Public License as 00014 published by the Free Software Foundation; either version 3 of the 00015 License, or (at your option) any later version. 00016 00017 The yat library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with yat. If not, see <http://www.gnu.org/licenses/>. 00024 */ 00025 00026 #include "iterator_traits.h" 00027 00028 #include <boost/concept_check.hpp> 00029 #include <boost/iterator/iterator_adaptor.hpp> 00030 #include <boost/type_traits/remove_reference.hpp> 00031 00032 namespace theplu { 00033 namespace yat { 00034 namespace utility { 00035 00060 template<typename Base> 00061 class WeightIterator 00062 : public boost::iterator_adaptor< 00063 WeightIterator<Base> // Derived 00064 , Base // Base 00065 , typename boost::remove_reference<typename iterator_traits<Base>::weight_reference>::type 00066 , boost::use_default // CategoryOrTraversal 00067 , typename iterator_traits<Base>::weight_reference // Reference 00068 > 00069 00070 { 00071 public: 00077 WeightIterator(void) 00078 : WeightIterator::iterator_adaptor_() 00079 { 00080 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>)); 00081 } 00082 00086 explicit WeightIterator(Base b) 00087 : WeightIterator::iterator_adaptor_(b) 00088 { 00089 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>)); 00090 } 00091 00100 template<typename B2> 00101 WeightIterator(WeightIterator<B2> other, 00102 typename boost::enable_if_convertible<B2, Base>::type* = 0 ) 00103 : WeightIterator::iterator_adaptor_(other.base()) {} 00104 00110 typename iterator_traits<Base>::weight_reference operator*(void) const 00111 { return iterator_traits<Base>().weight(this->base()); } 00112 00113 private: 00114 }; 00115 00123 template<typename Base> 00124 WeightIterator<Base> weight_iterator(Base base) 00125 { 00126 return WeightIterator<Base>(base); 00127 } 00128 00129 00130 00131 }}} // of namespace utility, yat, and theplu 00132 00133 #endif