magic_get
cppreference-doc
Our great sponsors
magic_get | cppreference-doc | |
---|---|---|
9 | 56 | |
193 | 398 | |
- | - | |
8.2 | 0.0 | |
5 months ago | about 1 year ago | |
C++ | HTML | |
Boost Software License 1.0 | GNU General Public License v3.0 only |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
magic_get
-
What is a good way to iterate through struct contents?
Maybe this: https://github.com/apolukhin/magic_get
-
What information about a type/class can we get?
You can access non-static member variables with structured bindings. See for instance magic_get/boostPfr https://github.com/apolukhin/magic_get. Structured bindings will only bind to the accessible members (not private). Magic get works by by finding the number of member variables, converting the struct to a tuple (with a function that is specialized for the number of fields), and finally accessing the members through the tuple (supporting indexing and iteration). It does not grant access to the member names, but it is sufficient for some reflection.
-
A way to determine the number of elements in a structured binding
Libraries like magic_get expose the members of an aggregate class/struct to allow writing generic code for things like pretty printing and serialization without anything special done to the class itself. They often rely on structured bindings for the decomposition (*), but find the number of elements via SFINAE on aggregate initialization, as an aggregate type can be initialized only from as many objects as it has members. It would be nicer if you could SFINAE directly on the structured binding itself, as then the type could have user-defined constructors (which aggregates can't). Unfortunately, this is not possible since structured binding is a statement and not an expression. Unless you're using Clang, where the GNU statement expressions extension allows you to do SFINAE on them, as in here.
-
Minimum viable declarative GUI in C++
No RTTI required, but the types are required to be aggregates (no constructors defined). It's possible to count the number of members using SFINAE by trying different numbers of inputs to the aggregate constructor using a type that's castable to anything, and then enumerate the members with a similar trick (or use structured binding to pull them out directly). I think he uses magic_get which is the most popular library for this trick.
-
Call function on each member of struct using preprocessor
take a look at magic_get to get access to all struct members. No idea what your plan is with foo and the preprocessor though.
-
Serdepp 0.1.2 Released
Neat! Have you considered using magic_get?
-
Getting information about classes, methods and variables in C++?
It is possible with some hacks https://github.com/apolukhin/magic_get
- Struct bulk operations - Reflection? Code gen?
-
Reflecting Over Members of an Aggregate
I actually reference it near the bottom of the article under its original name, magic_get! I was disappointed to discover that this library did it a similar way first before me while researching 😅
cppreference-doc
-
Looking for well written, modern C++ (17/20) example projects for microcontrollers
Rather than looking at good examples (which you should by all means do), add cppreference.com to you bookmarks and use it as your reference. By far the best C++ reference on the net. (from a C programmer who was thrown into C++ a decade ago -- slowly digesting C++20 now) Both StackOverflow.com and electronic.stackexchange.com are two additional QA sites that can help.
-
My first C++ project! A "mostly sane" C++ coroutine helper library
Sadly, not much. My method of learning is to get my hands dirty and waste a lot of time doing things wrong before I do them right. The only resource (outside of Google and StackOverflow) that I always had open was https://en.cppreference.com
-
C++ switch problem
In general, https://en.cppreference.com is your friend.
-
Can sanitizers find the two bugs I wrote in C++?
> As a C++ language reference I highly recommend https://en.cppreference.com
I'd be careful about such re-formulations of the Standard. When I was adding printf format checking to the D compiler, I discovered there were subtle discrepancies in the description of exactly how printf behaves. I went back to using the Standard.
-
Ask HN: What are great resources to catch up C++?
Modern C++ code now looks very different to even C++11 code which is considered to be the start of modern C++.
"A Tour of C++" which has already been recommended is probably a good start to get back in the game. I think there was a new version coming out, but not sure what the current status about this is.
[https://en.cppreference.com](cppreference.com) is a good resource for me. It has documentation regarding the new standards as well and up to C++20 the examples are mostly complete, at least for the relevant things.
I can also recommend watching the "Back to Basics" talks on the CppCon youtube channel and once you are more familiar also the regular talks. They are great resources about practical topics.
Jason Turner's C++ Weekly videos are also a great resource. They are usually 10-15 minutes long videos that give you a good start to think about. Great way to learn something new every week.
-
Why did rust Settle on snake_case?
At Google, at least, the style guide says to use snake case for variable names in C++ (but camel case for classes). As far as I can tell, this is also the convention in the C++ standard library.
-
wget keeps downloading forever, and stuff I don't want
Lets say that there's a file at https://en.cppreference.com/ called preferences.c. The command to download it would be wget https://en.cppreference.com/preferences.c
-
I am stuck in tutorial hell
I would start with a direction of where to apply C++. Updating legacy code, working on embedded systems, creating financial application and creating high performant games are a few common option. Also sites like cppreference and Compiler Explorer/Godbolt are your friends in learning. CPlusPlus.com might help with legacy support as it stops with C++11.
-
C++ #include errors detected
Keep in mind that most YouTube C++ tutorials are garbage. Use www.learncpp.com instead as a tutorial, and https://en.cppreference.com as a language reference. Once you familiarize yourself with the language, you can learn the best practices using the C++ Core Guidelines.
-
I'm struggling
The important thing to remember is that a concept exist and roughly what it's called, so you can look it up when you need to. You don't need to keep all the details in your head, that's what we have en.cppreference.com for.
What are some alternatives?
pfr - std::tuple like methods for user defined types without any macro or boilerplate code
telescope-vimwiki.nvim - look through your vimwiki with your telescope
cling - The cling C++ interpreter
browser-compat-data - This repository contains compatibility data for Web technologies as displayed on MDN
serdepp - c++ serialize and deserialize adaptor library like rust serde.rs
cgi-lib - A FREE ANSI C library for CGI programming.
cppinsights - C++ Insights - See your source code with the eyes of a compiler
stdrev - Script for cppreference, to control the amount of visible content
CppCoreGuidelines - The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++
book - The Rust Programming Language
learn - Sources for learn.adacore.com