I have created a sample program, I am able build on windows but on linux getting below error
error:Code:TEST.HPP #include<iostream> #include <iterator> #include <vector> typedef int Int; using namespace std; template<class C, typename T> class poly_iterator : public iterator_traits<typename C::iterator> { private: // typedef poly_iterator<C,T> _Self; protected: typedef typename C::iterator I; //!< regular iterator of the underlying container I i; //! mimic inheritage from the regular iterator //! because we cannot simply derive from it since // some iterators are regular pointers public: operator I&() { return (I&)i; } //!<needed to use poly_iterator in algorithms transparently public: poly_iterator<C,T>() {}; poly_iterator<C,T>(const I& p):i(p) {}; //!< construction form const_poly_iterator T& operator*() {return (T&)*i;} T* operator->() {return (T*)&*i;} public: // compatibility with I iterator poly_iterator<C,T>& operator++() {++i; return *this;} poly_iterator<C,T>& operator--() {--i; return *this;} poly_iterator<C,T> operator+(const Int count) { I temp = i; temp += count; return poly_iterator<C,T>(temp); } poly_iterator<C,T> operator-(const Int count) { I temp = i; temp -= count; return poly_iterator<C,T>(temp); } poly_iterator<C,T>& operator++(Int) { i++; return *this; } poly_iterator<C,T>& operator--(Int) { i--; return *this; } bool operator<(const poly_iterator<C,T>& other) const { return i < other.i; } bool operator<(const I& other) const { return i < other; } bool operator<=(const poly_iterator<C,T>& other) const { return i <= other.i; } bool operator<=(const I& other) const { return i <= other; } bool operator>(const poly_iterator<C,T>& other) const { return i > other.i; } bool operator>(const I& other) const { return i > other; } bool operator>=(const poly_iterator<C,T>& other) const { return i >= other.i; } bool operator>=(const I& other) const { return i >= other; } bool operator==(const I& other) const { return i==other; } bool operator!=(const I& other) const { return i!=other; } bool operator==(const poly_iterator<C,T>& other) const { return i==other.i; } bool operator!=(const poly_iterator<C,T>& other) const { return i!=other.i; } }; TEST.CPP //#include "stdafx.h" // iterator_traits.cpp // compile with: /EHsc #include <iostream> #include <iterator> #include <vector> #include <list> #include <algorithm> using namespace std; #include "test.hpp" int main() { vector<int> v(10); v[4] = 42; poly_iterator<vector<int>, int> it; poly_iterator<vector<int>, int> first(v.begin()); poly_iterator<vector<int>, int> last(v.end()); it = find(first, last, 42); if (it != last) { cout << *it << '\n'; } return 0; }
epuser@VOPTENG01 ~/Consolidator/vaibhav $> g++ test.cpp -o test.exe
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function â_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â
test.cpp:20: instantiated from here
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:204: error: no match for âoperator-â in â__last - __firstâ
test.hpp:50: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>erator-(Int) [with C = std::vector<int, std::allocator<int> >, T = int]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t stderator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:316: instantiated from â_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = poly_iterator<std::vector<int, std::allocator<int> >, int>, _Tp = int]â
test.cpp:20: instantiated from here
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:225: error: no match for âoperator-â in â__last - __firstâ
test.hpp:50: note: candidates are: poly_iterator<C, T> poly_iterator<C, T>erator-(Int) [with C = std::vector<int, std::allocator<int> >, T = int]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:182: note: ptrdiff_t stderator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)



LinkBack URL
About LinkBacks
erator-(Int) [with C = std::vector<int, std::allocator<int> >, T = int]



