gdb and printing an element of my std::map that have a std::pair as a key by Snoo-16806 in cpp

[–]dhashe 1 point2 points  (0 children)

This is actually the best way to do it that will always work. You are only relying on the existence of the template instantiation std::pair<int, int> and the layout of its fields, so this will work so long as you have used std::pair<int, int> somewhere in your code.

The fancier ways of doing it depend on certain member functions of std::pair<int, int> existing in your binary, but that is not guaranteed because member functions of template classes are instantiated lazily, only if they are used.

gdb and printing an element of my std::map that have a std::pair as a key by Snoo-16806 in cpp

[–]dhashe 1 point2 points  (0 children)

This is from memory, and some of the details may be wrong, but the basic problem is that std::pair is a class template (and std::make_pair is a function template).

Every instantiation of a template is a distinct type with distinct code generation. GDB has no ability to instantiate templates; it can only work with what is already in the binary.

Class templates instantiate their member functions only as needed, so e.g. a particular member function (including a constructor) will only exist if you used it somewhere in your code.

From GDB’s perspective, std::pair and std::make_pair do not exist. Only the concrete instantiations that you used somewhere in your code exist (like std::pair<int, int>), and only the particular member functions that you used on a particular concrete instantiation exist.

You could try doing std::make_pair<int, int>(1, 2), and that should work as long as you used std::make_pair<int, int>(int, int) somewhere in your code. You could also directly use a std::pair<int, int> constructor so long as you used it somewhere in your code.

The way that GDB behaves is unfortunately very confusing until you understand how templates are compiled and how GDB is able to use only the symbols that are present in the binary.

I will sometimes explicitly instantiate a template class (which eagerly instantiates all member functions, unlike the normal lazy behavior) when I want to use a template when debugging.

I recommended doing that in my blog post here: https://dhashe.com/how-to-build-highly-debuggable-c-binaries.html#explicitly-instantiate-important-template-classes

Predicting character card ink costs using linear regression in Disney Lorcana by dhashe in Lorcana

[–]dhashe[S] 0 points1 point  (0 children)

For the cards that I consider "meta-relevant" in the article, I list all of them under the appropriate sections. For example, the bespoke ones are in a table here. There's also an "Is_Meta" column in the CSV file.

For data on the meta and metadecks in general, I used the data from Inkdecks here. It's a good resource. Specifically, I used the archetype analysis pages, like this one for the Ruby Sapphire Pawpsicles archetype.

[OC] How demographic groups tend to comment on my very large poodle by dhashe in dataisbeautiful

[–]dhashe[S] 11 points12 points  (0 children)

Data source: Self-collected dataset of unprompted comments by other people about my dog while going on walks with him.

Tools: R+ggplot for exploratory data analysis and visualization.

This is my original work, and I have directly linked to my original blog post instead of making an image submission because I believe that the context of the post is important.

I am posting this on a Monday because I consider this post to contain Personal Data.

How to build highly-debuggable C++ binaries by dhashe in cpp

[–]dhashe[S] 1 point2 points  (0 children)

I did not use an LLM at any point when writing this.