diff options
author | Grigoriy Chudnov <g.chudnov@gmail.com> | 2016-03-09 13:29:58 +0300 |
---|---|---|
committer | Kirk Shoop <kirk.shoop@microsoft.com> | 2016-03-09 09:05:33 -0800 |
commit | 3fbc416f3d59bf517a4e2802f5724bd697e0a36a (patch) | |
tree | da875ea31f2b6f44723cca15d9b334b16f0fffb4 /Rx | |
parent | 88e0243595ac056a546d49921f77fe89bbc6314f (diff) | |
download | RxCpp-3fbc416f3d59bf517a4e2802f5724bd697e0a36a.tar.gz |
add is_hashable check for strings (string, wstring, u16string, u32string)
Diffstat (limited to 'Rx')
-rw-r--r-- | Rx/v2/src/rxcpp/rx-util.hpp | 12 | ||||
-rw-r--r-- | Rx/v2/test/operators/distinct.cpp | 44 |
2 files changed, 56 insertions, 0 deletions
diff --git a/Rx/v2/src/rxcpp/rx-util.hpp b/Rx/v2/src/rxcpp/rx-util.hpp index cbc4956..233049e 100644 --- a/Rx/v2/src/rxcpp/rx-util.hpp +++ b/Rx/v2/src/rxcpp/rx-util.hpp @@ -695,6 +695,18 @@ struct filtered_hash<T, typename std::enable_if<std::is_integral<T>::value>::typ template <class T> struct filtered_hash<T, typename std::enable_if<std::is_pointer<T>::value>::type> : std::hash<T> { }; +template <class T> +struct filtered_hash<T, typename std::enable_if<std::is_same<std::string, T>::value>::type> : std::hash<T> { +}; +template <class T> +struct filtered_hash<T, typename std::enable_if<std::is_same<std::wstring, T>::value>::type> : std::hash<T> { +}; +template <class T> +struct filtered_hash<T, typename std::enable_if<std::is_same<std::u16string, T>::value>::type> : std::hash<T> { +}; +template <class T> +struct filtered_hash<T, typename std::enable_if<std::is_same<std::u32string, T>::value>::type> : std::hash<T> { +}; template<typename, typename C = rxu::types_checked> struct is_hashable diff --git a/Rx/v2/test/operators/distinct.cpp b/Rx/v2/test/operators/distinct.cpp index e53e069..77c69cd 100644 --- a/Rx/v2/test/operators/distinct.cpp +++ b/Rx/v2/test/operators/distinct.cpp @@ -295,3 +295,47 @@ SCENARIO("distinct - some changes", "[distinct][operators]"){ } } } + +SCENARIO("distinct - strings", "[distinct][operators]"){ + GIVEN("a source"){ + auto sc = rxsc::make_test(); + auto w = sc.create_worker(); + const rxsc::test::messages<std::string> on; + + auto xs = sc.make_hot_observable({ + on.next(150, "A"), + on.next(210, "B"), + on.next(220, "B"), + on.next(230, "B"), + on.next(240, "B"), + on.completed(250) + }); + + WHEN("distinct values are taken"){ + + auto res = w.start( + [xs]() { + return xs.distinct(); + } + ); + + THEN("the output only contains distinct items sent while subscribed"){ + auto required = rxu::to_vector({ + on.next(210, "B"), + on.completed(250) + }); + auto actual = res.get_observer().messages(); + REQUIRE(required == actual); + } + + THEN("there was 1 subscription/unsubscription to the source"){ + auto required = rxu::to_vector({ + on.subscribe(200, 250) + }); + auto actual = xs.subscriptions(); + REQUIRE(required == actual); + } + + } + } +}
\ No newline at end of file |