Skip to content

Support more map containers #433

Open

Description

@rdong8

I'd like to use response<vector<pair<T, U>>> or response<absl::flat_hash_map<T, U>> as my response type for HGETALL, but the adapter is hardcoded to only support the standard library associative containers:

template <class T>
struct impl_map {
using type = simple_impl<T>;
};
template <class Key, class Compare, class Allocator>
struct impl_map<std::set<Key, Compare, Allocator>> {
using type = set_impl<std::set<Key, Compare, Allocator>>;
};
template <class Key, class Compare, class Allocator>
struct impl_map<std::multiset<Key, Compare, Allocator>> {
using type = set_impl<std::multiset<Key, Compare, Allocator>>;
};
template <class Key, class Hash, class KeyEqual, class Allocator>
struct impl_map<std::unordered_set<Key, Hash, KeyEqual, Allocator>> {
using type = set_impl<std::unordered_set<Key, Hash, KeyEqual, Allocator>>;
};
template <class Key, class Hash, class KeyEqual, class Allocator>
struct impl_map<std::unordered_multiset<Key, Hash, KeyEqual, Allocator>> {
using type = set_impl<std::unordered_multiset<Key, Hash, KeyEqual, Allocator>>;
};
template <class Key, class T, class Compare, class Allocator>
struct impl_map<std::map<Key, T, Compare, Allocator>> {
using type = map_impl<std::map<Key, T, Compare, Allocator>>;
};
template <class Key, class T, class Compare, class Allocator>
struct impl_map<std::multimap<Key, T, Compare, Allocator>> {
using type = map_impl<std::multimap<Key, T, Compare, Allocator>>;
};
template <class Key, class Hash, class KeyEqual, class Allocator>
struct impl_map<std::unordered_map<Key, Hash, KeyEqual, Allocator>> {
using type = map_impl<std::unordered_map<Key, Hash, KeyEqual, Allocator>>;
};
template <class Key, class Hash, class KeyEqual, class Allocator>
struct impl_map<std::unordered_multimap<Key, Hash, KeyEqual, Allocator>> {
using type = map_impl<std::unordered_multimap<Key, Hash, KeyEqual, Allocator>>;
};

It's also missing the new ones from C++23 (ie. flat_map). It would ideally support anything with a "map-like" interface.

Activity

  1. anarthal commented on Jul 10, 2026

    @anarthal
    Collaborator

    Thanks for reporting. I think we have two (potentially compatible) courses of action:

    1. We support "map-like" as you propose. We currently use insert() as part of the map implementation, so this would allow you to use the absl containers, the C++23 containers and the ones in Boost.Unordered, but not vector<pair<T, U>> because vector has no insert.
    2. We make the adapter interface public.

    I think 2 should be the ultimate goal, but starting with 1 seems wiser. The adapter interface looks pretty convoluted at the moment, so we'd probably have to revisit it before documenting it.

    @mzimbres what do you think?

  2. mzimbres commented on Jul 13, 2026

    @mzimbres
    Collaborator

    Hi, I will investigate.

  3. mzimbres commented on Aug 8, 2026

    @mzimbres
    Collaborator

    Hi, support for response<vector<pair<T, U>>> is now available in the develop branch https://github.com/boostorg/redis/blob/develop/example/cpp20_containers.cpp#L94-L96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions