Sierra Toolkit Version of the Day
random_access_iterator_wrapper.hpp
00001 #ifndef stk_util_util_random_access_iterator_wrapper_hpp
00002 #define stk_util_util_random_access_iterator_wrapper_hpp
00003 
00004 #include <boost/iterator/iterator_adaptor.hpp>
00005 
00006 #ifndef BOOST_NO_SFINAE
00007 # include <boost/type_traits/is_convertible.hpp>
00008 # include <boost/utility/enable_if.hpp>
00009 #endif
00010 
00011 namespace stk_util {
00012 
00013 
00014 template <class Value>
00015 class random_access_iterator_wrapper
00016   : public boost::iterator_adaptor<
00017         random_access_iterator_wrapper<Value>   // Derived
00018       , Value*                                  // Base
00019       , boost::use_default                      // Value
00020       , boost::random_access_traversal_tag      // CategoryOrTraversal
00021     >
00022 {
00023   private:
00024 
00025     typedef boost::iterator_adaptor<
00026                                      random_access_iterator_wrapper<Value>,
00027                                      Value*,
00028                                      boost::use_default,
00029                                      boost::random_access_traversal_tag
00030                                    > base_type;
00031 
00032     struct enabler {};  // used to enable coversion constructor (if SFINAE)
00033 
00034   public:
00035     random_access_iterator_wrapper()
00036       : base_type(0) {}
00037 
00038     explicit random_access_iterator_wrapper(Value* p)
00039       : base_type(p) {}
00040 
00041     Value& operator[] (ptrdiff_t index)
00042     { return *(*this + index); }
00043 
00044     template <class OtherValue>
00045       random_access_iterator_wrapper(
00046           random_access_iterator_wrapper<OtherValue> const& other
00047 # ifndef BOOST_NO_SFINAE
00048           , typename boost::enable_if<
00049           boost::is_convertible<OtherValue*,Value*>
00050           , enabler
00051           >::type = enabler()
00052 # endif
00053           )
00054       : base_type(other.base()) {}
00055 };
00056 
00057 }//namespace stk_util
00058 
00059 #endif
00060 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines