|
|
@@ -112,9 +112,6 @@ namespace stream {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-#define STREAM_BASE_COPY() \
|
|
|
- copy(other.copy), do_begin(other.do_begin), do_end(other.do_end), destroy(other.destroy)
|
|
|
-
|
|
|
template <typename T>
|
|
|
class stream_base : public stream_base_pointer_impl<T> {
|
|
|
private:
|
|
|
@@ -128,37 +125,12 @@ namespace stream {
|
|
|
using clean = typename std::decay<T>::type;
|
|
|
public:
|
|
|
template <typename Stream>
|
|
|
- stream_base(Stream * && impl) {
|
|
|
- copy = [](void * p) { return (void*) new Stream(*(Stream*)(p)); };
|
|
|
- do_begin = [](void * p) -> iterator<T> { return ((Stream*) p)->begin(); };
|
|
|
- do_end = [](void * p) -> iterator<T> { return ((Stream*) p)->end(); };
|
|
|
- destroy = [](void * p) { delete ((Stream*) p); };
|
|
|
- impl_ = impl;
|
|
|
- }
|
|
|
-
|
|
|
- stream_base(stream_base const & other)
|
|
|
- : STREAM_BASE_COPY()
|
|
|
- , impl_(copy(other.impl_)) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- stream_base(stream_base && other)
|
|
|
- : STREAM_BASE_COPY()
|
|
|
- , impl_(other.impl_) {
|
|
|
- other.impl_ = nullptr;
|
|
|
+ stream_base(std::shared_ptr<Stream> && impl) {
|
|
|
+ do_begin = [](std::shared_ptr<void> p) -> iterator<T> { return std::static_pointer_cast<Stream>(p)->begin(); };
|
|
|
+ do_end = [](std::shared_ptr<void> p) -> iterator<T> { return std::static_pointer_cast<Stream>(p)->end(); };
|
|
|
+ impl_ = std::static_pointer_cast<void>(impl);
|
|
|
}
|
|
|
|
|
|
- stream_base & operator=(stream_base const & other) {
|
|
|
- return *this = stream_base{other};
|
|
|
- }
|
|
|
-
|
|
|
- stream_base & operator=(stream_base && other) {
|
|
|
- swap(*this, other);
|
|
|
- return *this;
|
|
|
- }
|
|
|
-
|
|
|
- ~stream_base() { if (destroy) destroy(impl_); }
|
|
|
-
|
|
|
::stream::iterator<T> begin() const { return do_begin(impl_); }
|
|
|
::stream::iterator<T> end () const { return do_end (impl_); }
|
|
|
|
|
|
@@ -214,11 +186,9 @@ namespace stream {
|
|
|
template <typename F>
|
|
|
stream_base<flatmap_f<F>> flatmap(F&& func) const;
|
|
|
private:
|
|
|
- void* (*copy)(void*){nullptr};
|
|
|
- iterator<T> (*do_begin)(void*){nullptr};
|
|
|
- iterator<T> (*do_end)(void*){nullptr};
|
|
|
- void(*destroy)(void*){nullptr};
|
|
|
- void* impl_{nullptr};
|
|
|
+ iterator<T> (*do_begin)(std::shared_ptr<void>){nullptr};
|
|
|
+ iterator<T> (*do_end)(std::shared_ptr<void>){nullptr};
|
|
|
+ std::shared_ptr<void> impl_{nullptr};
|
|
|
};
|
|
|
}
|
|
|
}
|