summaryrefslogtreecommitdiff
path: root/Rx/v2
diff options
context:
space:
mode:
authorGrigoriy Chudnov <g.chudnov@gmail.com>2017-01-08 20:40:49 +0300
committerKirk Shoop <kirk.shoop@microsoft.com>2017-01-08 10:38:57 -0800
commita5a3f310d3358aa3628a694c44e45d746a193470 (patch)
tree85b5c14ae6bfeeac31dc385ae84cb110a0e0bd65 /Rx/v2
parentedd7d06673589ec3e2291bfad4f042f90e2cc25d (diff)
downloadRxCpp-a5a3f310d3358aa3628a694c44e45d746a193470.tar.gz
decouple skip_last from observable
Diffstat (limited to 'Rx/v2')
-rw-r--r--Rx/v2/src/rxcpp/operators/rx-skip_last.hpp72
-rw-r--r--Rx/v2/src/rxcpp/rx-includes.hpp1
-rw-r--r--Rx/v2/src/rxcpp/rx-observable.hpp27
-rw-r--r--Rx/v2/src/rxcpp/rx-operators.hpp8
-rw-r--r--Rx/v2/test/operators/skip_last.cpp5
5 files changed, 72 insertions, 41 deletions
diff --git a/Rx/v2/src/rxcpp/operators/rx-skip_last.hpp b/Rx/v2/src/rxcpp/operators/rx-skip_last.hpp
index 1a9681a..6641bd8 100644
--- a/Rx/v2/src/rxcpp/operators/rx-skip_last.hpp
+++ b/Rx/v2/src/rxcpp/operators/rx-skip_last.hpp
@@ -2,6 +2,21 @@
#pragma once
+/*! \file rx-skip_last.hpp
+
+ \brief Make new observable with skipped last count items from this observable.
+
+ \tparam Count the type of the items counter.
+
+ \param t the number of last items to skip.
+
+ \return An observable that is identical to the source observable except that it does not emit the last t items that the source observable emits.
+
+ \sample
+ \snippet skip_last.cpp skip_last sample
+ \snippet output.txt skip_last sample
+*/
+
#if !defined(RXCPP_OPERATORS_RX_SKIP_LAST_HPP)
#define RXCPP_OPERATORS_RX_SKIP_LAST_HPP
@@ -13,6 +28,16 @@ namespace operators {
namespace detail {
+template<class... AN>
+struct skip_last_invalid_arguments {};
+
+template<class... AN>
+struct skip_last_invalid : public rxo::operator_base<skip_last_invalid_arguments<AN...>> {
+ using type = observable<skip_last_invalid_arguments<AN...>, skip_last_invalid<AN...>>;
+};
+template<class... AN>
+using skip_last_invalid_t = typename skip_last_invalid<AN...>::type;
+
template<class T, class Observable, class Count>
struct skip_last : public operator_base<T>
{
@@ -89,31 +114,40 @@ struct skip_last : public operator_base<T>
}
};
-template<class T>
-class skip_last_factory
-{
- typedef rxu::decay_t<T> count_type;
- count_type count;
-public:
- skip_last_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_last<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>> {
- return observable<rxu::value_type_t<rxu::decay_t<Observable>>, skip_last<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>>(
- skip_last<rxu::value_type_t<rxu::decay_t<Observable>>, Observable, count_type>(std::forward<Observable>(source), count));
- }
-};
-
}
-template<class T>
-auto skip_last(T&& t)
- -> detail::skip_last_factory<T> {
- return detail::skip_last_factory<T>(std::forward<T>(t));
+/*! @copydoc rx-skip_last.hpp
+*/
+template<class... AN>
+auto skip_last(AN&&... an)
+ -> operator_factory<skip_last_tag, AN...> {
+ return operator_factory<skip_last_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
}
}
+template<>
+struct member_overload<skip_last_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 SkipLast = rxo::detail::skip_last<SourceValue, rxu::decay_t<Observable>, rxu::decay_t<Count>>,
+ class Value = rxu::value_type_t<SkipLast>,
+ class Result = observable<Value, SkipLast>>
+ static Result member(Observable&& o, Count&& c) {
+ return Result(SkipLast(std::forward<Observable>(o), std::forward<Count>(c)));
+ }
+
+ template<class... AN>
+ static operators::detail::skip_last_invalid_t<AN...> member(AN...) {
+ std::terminate();
+ return {};
+ static_assert(sizeof...(AN) == 10000, "skip_last takes (Count)");
+ }
+};
+
}
#endif
diff --git a/Rx/v2/src/rxcpp/rx-includes.hpp b/Rx/v2/src/rxcpp/rx-includes.hpp
index 2c565f9..7effb4b 100644
--- a/Rx/v2/src/rxcpp/rx-includes.hpp
+++ b/Rx/v2/src/rxcpp/rx-includes.hpp
@@ -208,6 +208,7 @@
#include "operators/rx-sample_time.hpp"
#include "operators/rx-sequence_equal.hpp"
#include "operators/rx-skip.hpp"
+#include "operators/rx-skip_last.hpp"
#include "operators/rx-take.hpp"
#include "operators/rx-take_last.hpp"
#include "operators/rx-take_until.hpp"
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp
index 1179d74..57a704e 100644
--- a/Rx/v2/src/rxcpp/rx-observable.hpp
+++ b/Rx/v2/src/rxcpp/rx-observable.hpp
@@ -1997,33 +1997,22 @@ public:
*/
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
+ /// \cond SHOW_SERVICE_MEMBERS
+ -> decltype(observable_member(skip_tag{}, *(this_type*)nullptr, std::forward<AN>(an)...))
+ /// \endcond
{
return observable_member(skip_tag{}, *this, std::forward<AN>(an)...);
}
- /*! Make new observable with skipped last count items from this observable.
-
- \tparam Count the type of the items counter
-
- \param t the number of last items to skip
-
- \return An observable that is identical to the source observable except that it does not emit the last t items that the source observable emits.
-
- \sample
- \snippet skip_last.cpp skip_last sample
- \snippet output.txt skip_last sample
+ /*! @copydoc rx-skip_last.hpp
*/
- template<class Count>
- auto skip_last(Count t) const
+ template<class... AN>
+ auto skip_last(AN... an) const
/// \cond SHOW_SERVICE_MEMBERS
- -> observable<T, rxo::detail::skip_last<T, this_type, Count>>
+ -> decltype(observable_member(skip_last_tag{}, *(this_type*)nullptr, std::forward<AN>(an)...))
/// \endcond
{
- return observable<T, rxo::detail::skip_last<T, this_type, Count>>(
- rxo::detail::skip_last<T, this_type, Count>(*this, t));
+ return observable_member(skip_last_tag{}, *this, std::forward<AN>(an)...);
}
/*! Make new observable with items skipped until on_next occurs on the trigger observable
diff --git a/Rx/v2/src/rxcpp/rx-operators.hpp b/Rx/v2/src/rxcpp/rx-operators.hpp
index 4946af6..2469a23 100644
--- a/Rx/v2/src/rxcpp/rx-operators.hpp
+++ b/Rx/v2/src/rxcpp/rx-operators.hpp
@@ -106,7 +106,6 @@ public:
#include "operators/rx-ref_count.hpp"
#include "operators/rx-replay.hpp"
#include "operators/rx-scan.hpp"
-#include "operators/rx-skip_last.hpp"
#include "operators/rx-skip_until.hpp"
#include "operators/rx-start_with.hpp"
#include "operators/rx-subscribe.hpp"
@@ -318,6 +317,13 @@ struct skip_tag {
};
};
+struct skip_last_tag {
+ template<class Included>
+ struct include_header{
+ static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_last.hpp>");
+ };
+};
+
struct take_tag {
template<class Included>
struct include_header{
diff --git a/Rx/v2/test/operators/skip_last.cpp b/Rx/v2/test/operators/skip_last.cpp
index f67e965..7da7aee 100644
--- a/Rx/v2/test/operators/skip_last.cpp
+++ b/Rx/v2/test/operators/skip_last.cpp
@@ -1,4 +1,5 @@
#include "../test.h"
+#include <rxcpp/operators/rx-skip_last.hpp>
SCENARIO("skip last 0", "[skip_last][operators]"){
GIVEN("a source"){
@@ -20,9 +21,9 @@ SCENARIO("skip last 0", "[skip_last][operators]"){
auto res = w.start(
[xs]() {
return xs
- .skip_last(0)
+ | rxo::skip_last(0)
// forget type to workaround lambda deduction bug on msvc 2013
- .as_dynamic();
+ | rxo::as_dynamic();
}
);