OSDN Git Service

iterator: *(a-1) に対応させるべく _linear_iterator_arithmetic を追加したりと奮闘中なう。
authorMyun2 <myun2@nwhite.info>
Thu, 3 Jun 2010 04:39:34 +0000 (13:39 +0900)
committerMyun2 <myun2@nwhite.info>
Thu, 3 Jun 2010 04:39:34 +0000 (13:39 +0900)
roast/include/roast/container/begin_end_iterator.hpp
roast/include/roast/container/indexer_iterator.hpp
roast/include/roast/container/iterator_base.hpp
roast/include/roast/container/linear_iterator_base.hpp
roast/test/roast_test_VC90/iterator_test.cpp

index 972eba3..fc25cee 100644 (file)
@@ -17,7 +17,7 @@ namespace roast
        {
                typedef _linear_iterator_impl_base<_Iterator> _Base;
        public:
-               typedef _Iterator _IteratorType;
+               typedef _Iterator IteratorType,_IteratorType;
                //typedef T _T, _Ty, _Value, _ValueType, ValueType;
                typedef _Iterator ValueType;
        protected:
index 2dadb60..fc2db2e 100644 (file)
@@ -120,8 +120,7 @@ namespace roast{
        ////////////////
        
        template <typename _ContainerType, typename _ValueType>
-       _linear_iterator_arithmetic<
-               _indexer_iterator_impl<_ContainerType,_ValueType>>
+       typename indexer_iterator<_ContainerType,_ValueType>::type
                make_indexer_iterator(_ContainerType con, _ValueType value)
        {
                return _linear_iterator_arithmetic<
index b6a80c5..ef427fe 100644 (file)
@@ -71,6 +71,8 @@ namespace roast{
        private:
                typedef _IteratorImpl _Base,_Impl,Impl;
        public:
+               typedef _IteratorImpl __Base__iterator;
+       public:
                typedef typename _IteratorImpl::ValueType _ValueType,ValueType;
                        
                typedef typename
index 82bb7e8..d4d1dc7 100644 (file)
@@ -53,6 +53,7 @@ namespace roast
                        return m_it;
                }
                
+               /*
                ///////////////////////////////////////////////////////////////////////
                
                //      Arithmetic operators
@@ -83,9 +84,53 @@ namespace roast
                {
                        return _linear_iterator_impl_base(m_it + n);
                }
+               */
        };
        
        /////////////////////////////////////////////////////////
+       /////////////////////////////////////////////////////////
+
+       template <typename _Impl>
+       class _linear_iterator_arithmetic : public _Impl
+       {
+       private:
+               typedef _Impl _Base;
+               typedef _linear_iterator_arithmetic<_Base> _Self;
+               typedef typename _Base::IteratorType IteratorType;
+       public:
+               ///////////////////////////////////////////////////////////////////////
+               
+               //      Arithmetic operators
+               
+               int operator -(const _Self& target) const
+               {
+                       return m_it - target.m_it;
+               }
+               int operator -(const IteratorType& target) const
+               {
+                       return m_it - target;
+               }
+               _Self operator -(int n) const
+               {
+                       return _Self(m_it - n);
+               }
+               _Self operator --() {
+                       _Self old = *this;
+                       m_it--;
+                       return old;
+               }
+               _Self operator --(int) {
+                       m_it--;
+                       return *this;
+               }
+               
+               _Self operator +(int n) const
+               {
+                       return _Self(m_it + n);
+               }
+       };
+               
+       /////////////////////////////////////////////////////////
 
        template <typename T>
        class linear_iterator_base :
index 5a79727..aa4429c 100644 (file)
@@ -4,17 +4,31 @@
 
 using namespace roast;
 
+template <typename T>
+class A
+{
+};
+
+template <typename C>
+class B : public A<C>
+{
+
+};
+
 void main()
 {
+       B<int> aaa;
+
        char work[32];
 
-       indexer_iterator<char*, char>::type a = indexer_iterator_impl<char*, char>(work, (size_t)32);
+       //indexer_iterator<char*, char>::type a = _indexer_iterator_impl<char*, char>(work,32);
+       indexer_iterator<char*, char>::type a = make_indexer_iterator<char*, char>(work,32);
        do
        {
-               *a = 0;
+               *a = *(a-1);
        }while(a.in_dowhile());
 
-       a = indexer_iterator_impl<char*, char>(work, (size_t)32);
+       a = make_indexer_iterator<char*, char>(work,32);
        do
        {
                printf("%d, ", *a);