summaryrefslogtreecommitdiff
path: root/Rx
diff options
context:
space:
mode:
authorKirk Shoop <kirk.shoop@microsoft.com>2016-03-09 09:01:20 -0800
committerKirk Shoop <kirk.shoop@microsoft.com>2016-03-09 09:05:34 -0800
commit7370f1e40ecae90f39b66a91f57ed61b41cf107e (patch)
tree0bf0ecbb513d79f42027ebe44c77724307ababea /Rx
parent9b26e478f666d8a6ae58a0bf630e8fa5530f82d3 (diff)
downloadRxCpp-7370f1e40ecae90f39b66a91f57ed61b41cf107e.tar.gz
add is_string<T>
support all basic_string types add note about filtered_hash<T> whitelist
Diffstat (limited to 'Rx')
-rw-r--r--Rx/v2/src/rxcpp/rx-observable.hpp4
-rw-r--r--Rx/v2/src/rxcpp/rx-util.hpp36
2 files changed, 26 insertions, 14 deletions
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp
index bbc0274..e2646ed 100644
--- a/Rx/v2/src/rxcpp/rx-observable.hpp
+++ b/Rx/v2/src/rxcpp/rx-observable.hpp
@@ -824,7 +824,7 @@ public:
\param s the selector function
\return Observable that emits the items from the source observable, transformed by the specified function.
-
+
\sample
\snippet map.cpp map sample
\snippet output.txt map sample
@@ -886,6 +886,8 @@ public:
\return Observable that emits those items from the source observable that are distinct.
+ \note distinct keeps an unordered_set<T> of past values. Due to an issue in multiple implementations of std::hash<T>, rxcpp maintains a whitelist of hashable types. new types can be added by specializing rxcpp::filtered_hash<T>
+
\sample
\snippet distinct.cpp distinct sample
\snippet output.txt distinct sample
diff --git a/Rx/v2/src/rxcpp/rx-util.hpp b/Rx/v2/src/rxcpp/rx-util.hpp
index 233049e..d25b76f 100644
--- a/Rx/v2/src/rxcpp/rx-util.hpp
+++ b/Rx/v2/src/rxcpp/rx-util.hpp
@@ -674,18 +674,37 @@ public:
};
#endif
+template<typename, typename C = types_checked>
+struct is_string : std::false_type {
+};
+
+template <typename T>
+struct is_string<T,
+ typename types_checked_from<
+ typename T::value_type,
+ typename T::traits_type,
+ typename T::allocator_type>::type>
+ : std::is_base_of<
+ std::basic_string<
+ typename T::value_type,
+ typename T::traits_type,
+ typename T::allocator_type>, T> {
+};
+
}
namespace rxu=util;
+
//
// due to an noisy static_assert issue in more than one std lib impl,
-// build a whitelist filter for the types that are allowed to be hashed
-// in rxcpp. this allows is_hashable<T> to work.
+// rxcpp maintains a whitelist filter for the types that are allowed
+// to be hashed. this allows is_hashable<T> to work.
//
// NOTE: this should eventually be removed!
//
template <class T, typename = void>
struct filtered_hash;
+
template <class T>
struct filtered_hash<T, typename std::enable_if<std::is_enum<T>::value>::type> : std::hash<T> {
};
@@ -695,17 +714,8 @@ 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 <class T>
+struct filtered_hash<T, typename std::enable_if<rxu::is_string<T>::value>::type> : std::hash<T> {
};
template<typename, typename C = rxu::types_checked>