Posted Joe Chucpp4 minutes read (About 647 words)0 visits
C++ Insights Tool
C++ Insights is an open-source tool that transforms C++ source code into a representation closer to what compiler sees and generates. It helps understand the underlying details of C++.
A binary release is available, allowing you to install the tool on your local machine. Upon opening it in the browser, a default example is displayed, demonstrating its capabilities. The left pane shows the input C++ source code, while the right pane presents the translated version enriched with additional information.
2. Translating range-based for loop
before.cpp
1 2 3 4 5 6 7
intmain(){ std::vector<int> numbers = {1, 2, 3, 4, 5}; for (int num : numbers) { std::cout << num << " "; } return0; }
#include<initializer_list> int a = 3; constint ca = a; constint & ra = static_cast<constint>(a); int & ref1 = a; constint & ref2 = ca; int && ref3 = 3; int a1 = 3; int a2 = 3; std::initializer_list<int> a3 = std::initializer_list<int>{1}; int a4 = {3}; int * p; constint * cp; constint *const ccp = cp; int * b1 = p; constint * b2 = cp; constint * b3 = ccp;
When using auto, the deduced type will:
Preserve top-level const for references.
Ignore top-level const for non-reference types.
Here, ccp is not a reference, so the top-level const (the const on the pointer itself) is ignored, while the low-level const (the const on the object being pointed to) is preserved.