3 #if !defined(CPPLINQ_LINQ_CURSOR_HPP) 4 #define CPPLINQ_LINQ_CURSOR_HPP 80 template <std::
size_t n>
struct type_to_size {
char value[n]; };
82 type_to_size<1> get_category_from_iterator(std::input_iterator_tag);
83 type_to_size<2> get_category_from_iterator(std::forward_iterator_tag);
84 type_to_size<3> get_category_from_iterator(std::bidirectional_iterator_tag);
85 type_to_size<4> get_category_from_iterator(std::random_access_iterator_tag);
88 template <std::
size_t>
94 static const std::size_t catIx =
sizeof(detail::get_category_from_iterator(
typename std::iterator_traits<Iter>::iterator_category()) );
106 template <
class Cat1,
class Cat2>
111 typedef struct {
char c1,c2; } no;
112 static yes invoke(Cat1);
113 static no invoke(...);
115 enum { value = (
sizeof(invoke(Cat2())) ==
sizeof(yes)) };
121 template <
class Cat1,
class Cat2,
class Cat3 =
void>
126 template <
class Cat1,
class Cat2>
129 less_or_equal_cursor_category<Cat2, Cat1>::value,
135 template <
class Collection>
137 typedef decltype(cursor(*static_cast<Collection*>(0))) type;
142 template <class Iterator>
148 typedef typename std::remove_reference<typename std::iterator_traits<Iterator>::value_type>::type
150 typedef typename std::iterator_traits<Iterator>::reference
156 bool empty()
const {
return current == fin; }
159 throw std::logic_error(
"inc past end");
162 typename std::iterator_traits<Iterator>::reference
get()
const {
return *current; }
164 bool atbegin()
const {
return current == start; }
166 if (current == start)
167 throw std::logic_error(
"dec past begin");
171 void skip(std::ptrdiff_t n) { current += n; }
172 std::size_t
size() {
return fin-start; }
175 if (n > fin-current) {
184 , fin(std::move(fin))
189 : current(std::move(current))
190 , start(std::move(start))
191 , fin(std::move(fin))
206 virtual bool empty()
const = 0;
207 virtual void inc() = 0;
210 virtual T
get()
const = 0;
223 instance(Cur cursor) : innerCursor(std::move(cursor))
226 virtual bool empty()
const 228 return innerCursor.empty();
234 virtual T
get()
const 236 return innerCursor.get();
240 return new instance(*
this);
244 std::unique_ptr<cursor_interface<T>> myCur;
254 : myCur(other.myCur ? other.myCur->copy() : nullptr)
259 : myCur(other.myCur.release())
263 template <
class Cursor>
265 : myCur(new instance<Cursor>(std::move(cursor)))
269 template <
class Iterator>
275 bool empty()
const {
return !myCur || myCur->empty(); }
276 void inc() { myCur->inc(); }
277 T
get()
const {
return myCur->get(); }
281 std::swap(myCur, other.myCur);
295 std::shared_ptr< container_interface<T> > container;
297 template <
class Container>
302 instance(Container c) : c(c)
308 return c.get_cursor();
318 : container(other.container)
323 template <
class Container>
325 : container(new instance<Container>(c))
330 template <
class Iterator>
342 #endif // !defined(CPPLINQ_LINQ_CURSOR_HPP dynamic_collection(Iterator begin, Iterator end)
Definition: linq_cursor.hpp:331
onepass_cursor_tag type
Definition: linq_cursor.hpp:98
void forget()
Definition: linq_cursor.hpp:155
dynamic_cursor(Cursor cursor)
Definition: linq_cursor.hpp:264
bidirectional_cursor_tag type
Definition: linq_cursor.hpp:100
bool empty() const
Definition: linq_cursor.hpp:156
Definition: linq_cursor.hpp:122
forward_cursor_tag type
Definition: linq_cursor.hpp:99
iter_to_cursor_category_< catIx >::type type
Definition: linq_cursor.hpp:95
void inc()
Definition: linq_cursor.hpp:276
dynamic_cursor(dynamic_cursor &&other)
Definition: linq_cursor.hpp:258
auto empty() -> decltype(from< T >())
Returns an observable that sends no items to observer and immediately completes, on the specified sch...
Definition: rx-empty.hpp:37
Definition: linq_cursor.hpp:68
Definition: linq_cursor.hpp:63
random_access_cursor_tag type
Definition: linq_cursor.hpp:101
Definition: linq_cursor.hpp:143
iter_cursor(Iterator start, Iterator fin, Iterator current)
Definition: linq_cursor.hpp:188
dynamic_cursor & operator=(dynamic_cursor other)
Definition: linq_cursor.hpp:279
Definition: linq_cursor.hpp:66
iter_cursor cursor
Definition: linq_cursor.hpp:146
void inc()
Definition: linq_cursor.hpp:157
std::iterator_traits< Iterator >::reference reference_type
Definition: linq_cursor.hpp:151
dynamic_cursor< T > cursor
Definition: linq_cursor.hpp:313
Definition: linq_cursor.hpp:64
iter_cursor get_cursor() const
Definition: linq_cursor.hpp:195
dynamic_cursor()
Definition: linq_cursor.hpp:251
std::remove_reference< T >::type element_type
Definition: linq_cursor.hpp:248
void position()
Definition: linq_cursor.hpp:173
Definition: linq_cursor.hpp:204
virtual ~cursor_interface()
Definition: linq_cursor.hpp:212
Definition: linq_cursor.hpp:287
Definition: linq_cursor.hpp:92
Definition: linq_cursor.hpp:293
dynamic_collection(const dynamic_collection &other)
Definition: linq_cursor.hpp:317
Definition: linq_cursor.hpp:61
Definition: linq_cursor.hpp:216
dynamic_collection()
Definition: linq_cursor.hpp:315
bool empty() const
Definition: linq_cursor.hpp:275
T reference_type
Definition: linq_cursor.hpp:249
Definition: linq_cursor.hpp:136
Definition: linq_cursor.hpp:65
Definition: linq_cursor.hpp:107
std::remove_reference< typename std::iterator_traits< Iterator >::value_type >::type element_type
Definition: linq_cursor.hpp:149
void skip(std::ptrdiff_t n)
Definition: linq_cursor.hpp:171
dynamic_cursor(const dynamic_cursor &other)
Definition: linq_cursor.hpp:253
bool atbegin() const
Definition: linq_cursor.hpp:164
auto get_cursor(const linq_take< Collection > &take) -> decltype(get_cursor_(take, typename Collection::cursor::cursor_category()))
Definition: linq_take.hpp:87
util::iter_to_cursor_category< Iterator >::type cursor_category
Definition: linq_cursor.hpp:153
void truncate(std::size_t n)
Definition: linq_cursor.hpp:174
std::size_t size()
Definition: linq_cursor.hpp:172
dynamic_cursor< T > get_cursor() const
Definition: linq_cursor.hpp:336
Definition: linq_cursor.hpp:69
Definition: linq_cursor.hpp:89
forward_cursor_tag cursor_category
Definition: linq_cursor.hpp:247
iter_cursor(Iterator start, Iterator fin)
Definition: linq_cursor.hpp:181
dynamic_collection(Container c)
Definition: linq_cursor.hpp:324
Definition: linq_cursor.hpp:70
dynamic_cursor(Iterator start, Iterator end)
Definition: linq_cursor.hpp:270
void dec()
Definition: linq_cursor.hpp:165