Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visualizer for std::flat_map #4887

Open
wants to merge 1 commit into
base: feature/flat_map
Choose a base branch
from

Conversation

Nerixyz
Copy link

@Nerixyz Nerixyz commented Aug 10, 2024

This PR adds visualizers for std::flat_map with any combination of std::vector and std::deque as the backing containers.

I'm not sure if there's a way of making this smaller. The only difference between the types is the implementation of size, key_at, and value_at - <Expand> is always the same. Ideally, there would be a way of having a condition based on the relevant type in from the template ($T4 for size and key_at; $T5 for value_at). Alternatively, it would be fine keeping just the type where both containers are vectors, since that's the default, and have the fallback that shows keys and values.

Initially, I had a <DisplayString>{{ size={size()} }}</DisplayString>, but I wanted to have at least some preview of the items contained in the map in the unexpanded view. Unfortunately, the [comparator] still shows up in the display string, so only one value is shown.

Code_2024-08-10_16-56-49

Code
#include <deque>
#include <flat_map>
#include <string>

template <typename KeyContainer, typename MappedContainer> auto make() {
  std::flat_map<int, std::string, std::less<int>, KeyContainer, MappedContainer>
      map;
  map.emplace(42, "hello world");
  map.emplace(1, "meow");
  map.emplace(2, "hey");
  return map;
}

int main() {
  auto vectorVector = make<std::vector<int>, std::vector<std::string>>();
  auto vectorDeque = make<std::vector<int>, std::deque<std::string>>();
  auto dequeVector = make<std::deque<int>, std::vector<std::string>>();
  auto dequeDeque = make<std::deque<int>, std::deque<std::string>>();
  return 0;
}

@Nerixyz Nerixyz requested a review from a team as a code owner August 10, 2024 15:05
@StephanTLavavej StephanTLavavej added visualizer How the VS debugger displays STL types flat_meow C++23 container adaptors labels Aug 11, 2024
@StephanTLavavej StephanTLavavej self-assigned this Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flat_meow C++23 container adaptors visualizer How the VS debugger displays STL types
Projects
Status: Initial Review
Development

Successfully merging this pull request may close these issues.

3 participants