summaryrefslogtreecommitdiff
path: root/Rx/v2/src
diff options
context:
space:
mode:
authorRafaƂ Borowiak <rborowiak@euvic.pl>2016-12-30 19:49:17 +0100
committerKirk Shoop <kirk.shoop@microsoft.com>2016-12-30 13:09:20 -0800
commit800030070b2daa0085bc9c0d34a975bc2555c5a1 (patch)
tree05bba8c06dbc6d5610825007e548eea026aae88e /Rx/v2/src
parentcb9d89cf9c3a2f422e3dfbe2de6226cbb5f21b26 (diff)
downloadRxCpp-800030070b2daa0085bc9c0d34a975bc2555c5a1.tar.gz
decouple skip from observable
Diffstat (limited to 'Rx/v2/src')
-rw-r--r--Rx/v2/src/rxcpp/operators/rx-skip.hpp74
-rw-r--r--Rx/v2/src/rxcpp/rx-includes.hpp1
-rw-r--r--Rx/v2/src/rxcpp/rx-observable.hpp25
-rw-r--r--Rx/v2/src/rxcpp/rx-operators.hpp8
4 files changed, 70 insertions, 38 deletions
diff --git a/Rx/v2/src/rxcpp/operators/rx-skip.hpp b/Rx/v2/src/rxcpp/operators/rx-skip.hpp
index 9e4611a..901748c 100644
--- a/Rx/v2/src/rxcpp/operators/rx-skip.hpp
+++ b/Rx/v2/src/rxcpp/operators/rx-skip.hpp
@@ -2,6 +2,21 @@
#pragma once
+/*! \file rx-skip.cpp
+
+ \brief Make new observable with skipped first count items from this observable.
+
+ \tparam Count the type of the items counter
+
+ \param t the number of items to skip
+
+ \return An observable that is identical to the source observable except that it does not emit the first t items that the source observable emits.
+
+ \sample
+ \snippet skip.cpp skip sample
+ \snippet output.txt skip sample
+*/
+
#if !defined(RXCPP_OPERATORS_RX_SKIP_HPP)
#define RXCPP_OPERATORS_RX_SKIP_HPP
@@ -13,6 +28,17 @@ namespace operators {
namespace detail {
+template<class... AN>
+struct skip_invalid_arguments {};
+
+template<class... AN>
+struct skip_invalid : public rxo::operator_base<skip_invalid_arguments<AN...>> {
+ using type = observable<skip_invalid_arguments<AN...>, skip_invalid<AN...>>;
+};
+
+template<class... AN>
+using skip_invalid_t = typename skip_invalid<AN...>::type;
+
template<class T, class Observable, class Count>
struct skip : public operator_base<T>
{
@@ -96,31 +122,41 @@ struct skip : public operator_base<T>
}
};
-template<class T>
-class skip_factory
-{
- typedef rxu::decay_t<T> count_type;
- count_type count;
-public:
- skip_factory(count_type t) : count(std::move(t)) {}
- template<class Observable>
- auto operator()(Observable&& source)
- -> observable<rxu::value_type_t<rxu::decay_t<Observable>>, skip<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>> {
- return observable<rxu::value_type_t<rxu::decay_t<Observable>>, skip<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>>(
- skip<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>(std::forward<Observable>(source), count));
- }
-};
-
}
-template<class T>
-auto skip(T&& t)
- -> detail::skip_factory<T> {
- return detail::skip_factory<T>(std::forward<T>(t));
+/*! @copydoc rx-skip.hpp
+*/
+template<class... AN>
+auto skip(AN&&... an)
+-> operator_factory<skip_tag, AN...> {
+ return operator_factory<skip_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
}
}
+template<>
+struct member_overload<skip_tag>
+{
+ template<class Observable,
+ class Count,
+ class Enabled = rxu::enable_if_all_true_type_t<
+ is_observable<Observable>>,
+ class SourceValue = rxu::value_type_t<Observable>,
+ class Skip = rxo::detail::skip<SourceValue, rxu::decay_t<Observable>, rxu::decay_t<Count>>,
+ class Value = rxu::value_type_t<Skip>,
+ class Result = observable<Value, Skip>>
+ static Result member(Observable&& o, Count&& c) {
+ return Result(Skip(std::forward<Observable>(o), std::forward<Count>(c)));
+ }
+
+ template<class... AN>
+ static operators::detail::skip_invalid_t<AN...> member(AN...) {
+ std::terminate();
+ return {};
+ static_assert(sizeof...(AN) == 10000, "skip takes (optional Count)");
+ }
+};
+
}
#endif
diff --git a/Rx/v2/src/rxcpp/rx-includes.hpp b/Rx/v2/src/rxcpp/rx-includes.hpp
index 98b060c..50dce24 100644
--- a/Rx/v2/src/rxcpp/rx-includes.hpp
+++ b/Rx/v2/src/rxcpp/rx-includes.hpp
@@ -204,6 +204,7 @@
#include "operators/rx-repeat.hpp"
#include "operators/rx-retry.hpp"
#include "operators/rx-sequence_equal.hpp"
+#include "operators/rx-skip.hpp"
#include "operators/rx-take.hpp"
#include "operators/rx-take_while.hpp"
#include "operators/rx-timeout.hpp"
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp
index 6b5dfe6..c534de4 100644
--- a/Rx/v2/src/rxcpp/rx-observable.hpp
+++ b/Rx/v2/src/rxcpp/rx-observable.hpp
@@ -2311,26 +2311,15 @@ public:
static_assert(sizeof...(AN) == 0, "sample_with_time(period) was passed too many arguments.");
}
- /*! Make new observable with skipped first count items from this observable.
-
- \tparam Count the type of the items counter
-
- \param t the number of items to skip
-
- \return An observable that is identical to the source observable except that it does not emit the first t items that the source observable emits.
-
- \sample
- \snippet skip.cpp skip sample
- \snippet output.txt skip sample
+ /*! @copydoc rx-skip.hpp
*/
- template<class Count>
- auto skip(Count t) const
- /// \cond SHOW_SERVICE_MEMBERS
- -> observable<T, rxo::detail::skip<T, this_type, Count>>
- /// \endcond
+ template<class... AN>
+ auto skip(AN... an) const
+ /// \cond SHOW_SERVICE_MEMBERS
+ -> decltype(observable_member(skip_tag{}, *(this_type*)nullptr, std::forward<AN>(an)...))
+ /// \endcond
{
- return observable<T, rxo::detail::skip<T, this_type, Count>>(
- rxo::detail::skip<T, this_type, Count>(*this, t));
+ return observable_member(skip_tag{}, *this, std::forward<AN>(an)...);
}
/*! Make new observable with skipped last count items from this observable.
diff --git a/Rx/v2/src/rxcpp/rx-operators.hpp b/Rx/v2/src/rxcpp/rx-operators.hpp
index cc599c6..7fe6b20 100644
--- a/Rx/v2/src/rxcpp/rx-operators.hpp
+++ b/Rx/v2/src/rxcpp/rx-operators.hpp
@@ -109,7 +109,6 @@ public:
#include "operators/rx-replay.hpp"
#include "operators/rx-sample_time.hpp"
#include "operators/rx-scan.hpp"
-#include "operators/rx-skip.hpp"
#include "operators/rx-skip_last.hpp"
#include "operators/rx-skip_until.hpp"
#include "operators/rx-start_with.hpp"
@@ -299,6 +298,13 @@ struct sequence_equal_tag {
};
};
+struct skip_tag {
+ template<class Included>
+ struct include_header{
+ static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip.hpp>");
+ };
+};
+
struct take_tag {
template<class Included>
struct include_header{