Skip to content

Add visualizer for std::flat_map#4887

Merged
CaseyCarter merged 6 commits intomicrosoft:feature/flat_mapfrom
Nerixyz:feat/flatmap-visualizer
Oct 24, 2024
Merged

Add visualizer for std::flat_map#4887
CaseyCarter merged 6 commits intomicrosoft:feature/flat_mapfrom
Nerixyz:feat/flatmap-visualizer

Conversation

@Nerixyz
Copy link
Contributor

@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. See #4887 (comment)

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
@Nerixyz
Copy link
Contributor Author

Nerixyz commented Oct 24, 2024

I added a <DisplayString> to be more in-line with the visualizers for std::map and std::unordered_map.

Preview

devenv_2024-10-24_18-43-25

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

static void fillMap(auto &map) {
  map.emplace(42, "hello world");
  map.emplace(1, "meow");
  map.emplace(2, "hey");
}

template <typename T> T make() {
  T map{};
  fillMap(map);
  return map;
}

template <typename KeyContainer, typename MappedContainer> auto make() {
  return make<std::flat_map<int, std::string, std::less<int>, KeyContainer,
                            MappedContainer>>();
}

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>>();

  auto stdMap = make<std::map<int, std::string>>();
  auto stdUnorderedMap = make<std::unordered_map<int, std::string>>();
  return 0;
}

@CaseyCarter CaseyCarter self-assigned this Oct 24, 2024
@CaseyCarter CaseyCarter merged commit dc266ed into microsoft:feature/flat_map Oct 24, 2024
@CaseyCarter
Copy link
Contributor

CaseyCarter commented Oct 24, 2024

Thanks for yet another great piece of visualizer work! Truly visionary. 👁️🕶️👓🥽👀

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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants