Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename I>
- class Foo
- {
- const I Begin ;
- const I End ;
- I Position;
- public:
- bool append(const I begin, const I end)
- {
- if(std::distance(begin, end) <= std::distance(Position, End))
- {
- Position = std::copy(begin,end,Position);
- return true;
- }
- return false;
- }
- };
- auto foo = Foo<int *>(/* как-то инициализируем */);
- const int data[] = {0,1,2,3,4,5,6,7};
- foo.append( std::begin(data)
- , std::end (data) );
- template<typename U>
- bool append(U begin, U end)
- {
- //... здесь так же
- }
- template<typename U>
- bool append(U begin, U end)
- {
- //... здесь так же
- }
- using T = typename std::add_pointer<
- typename std::add_const<
- typename std::remove_pointer<I>::type >
- ::type >::type;
- bool append(T begin, T end)
- ...
- #include <type_traits>
- #include <iterator>
- template<class T>
- struct is_const_iterator
- : std::is_const<std::iterator_traits<T>::reference>
- {};
- // для интераторов STL
- template<class T>
- struct iterator_traits_ex: std::iterator_traits<T>
- {
- typedef T original_iterator;
- //typedef /* не известно */ iterator;
- //typedef /* не известно */ const_iterator;
- };
- template<class T>
- struct iterator_traits_ex<T *>: std::iterator_traits<T*>
- {
- typedef T * original_iterator;
- typedef T * iterator;
- typedef const T * const_iterator;
- };
- template<class T>
- struct iterator_traits_ex<const T *>: std::iterator_traits<const T *>
- {
- typedef const T * original_iterator;
- typedef T * iterator;
- typedef const T * const_iterator;
- };
- template<typename I>
- class Foo
- {
- static_assert(!is_const_iterator<I>::value, "Type of I can't be a const iterator!");
- // ...
- typedef typename iterator_traits_ex<I>::const_iterator ConstIterator;
- public:
- bool append(ConstIterator begin, ConstIterator end)
- {
- // ...
- }
- };
Add Comment
Please, Sign In to add comment