refs #624 Modernize how CDictionary selects its default implementation container.

This commit is contained in:
Mathew Sutcliffe
2016-03-20 21:55:05 +00:00
parent a1861c69f0
commit 187501bb3c

View File

@@ -38,14 +38,16 @@ namespace BlackMisc
using ::BlackMisc::qHash; // bring hidden name into scope using ::BlackMisc::qHash; // bring hidden name into scope
template <class Key> template <class Key>
struct SupportsQHash : std::integral_constant<bool, constexpr static bool supportsQHash()
! std::is_same<decltype(std::declval<Key>() == std::declval<Key>()), NotFound>::value && {
! std::is_same<decltype(qHash(std::declval<Key>())), NotFound>::value return ! std::is_same<decltype(std::declval<Key>() == std::declval<Key>()), NotFound>::value &&
> {}; ! std::is_same<decltype(qHash(std::declval<Key>())), NotFound>::value;
};
template <class Key> template <class Key>
struct SupportsQMap : std::integral_constant<bool, constexpr static bool supportsQMap()
! std::is_same<decltype(std::declval<Key>() < std::declval<Key>()), NotFound>::value {
> {}; return ! std::is_same<decltype(std::declval<Key>() < std::declval<Key>()), NotFound>::value;
};
} }
template <bool KeySupportsQHash /* = true */, bool KeySupportsQMap> template <bool KeySupportsQHash /* = true */, bool KeySupportsQMap>
@@ -72,12 +74,11 @@ namespace BlackMisc
//! Trait to select the appropriate default associative container type depending on what the key type supports //! Trait to select the appropriate default associative container type depending on what the key type supports
template <class Key> template <typename K, typename V>
struct AssociativityTraits : public Private::AssociativityTraits<Private::ADL::SupportsQHash<Key>::value, Private::ADL::SupportsQMap<Key>::value> using DefaultAssociativeType = typename Private::AssociativityTraits<Private::ADL::supportsQHash<K>(), Private::ADL::supportsQMap<K>()>::template DefaultType<K, V>;
{};
//! Associative container with value semantics, chooses a sensible default implementation container type //! Associative container with value semantics, chooses a sensible default implementation container type
template<class Key, class Value, template <class...> class Impl = AssociativityTraits<Key>::template DefaultType> template<class Key, class Value, template <class...> class Impl = DefaultAssociativeType>
class CDictionary : class CDictionary :
public Mixin::DBusOperators<CDictionary<Key, Value, Impl>>, public Mixin::DBusOperators<CDictionary<Key, Value, Impl>>,
public Mixin::JsonOperators<CDictionary<Key, Value, Impl>>, public Mixin::JsonOperators<CDictionary<Key, Value, Impl>>,