Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
Join now: C++ Self Study + 1:1 Coaching
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <memory> template<typename T, size_t SIZE> struct Array { T mData[SIZE]; auto* data(this auto& self) { return std::addressof(self.mData[0]); } auto* begin(this auto& self) { return self.data(); } auto* end(this auto& self) { return self.data() + self.size(); } auto& operator[](this auto& s, size_t idx) { return s.mData[idx]; } constexpr size_t size() const { return SIZE; } }; int main() { const Array<int, 2> ai{3, 5}; Array<int, 2> ab{3, 5}; for(const auto& e : ai) {} for(auto& e : ab) {} auto e = ai[1]; // thanks to auto& temporaries are not allowed // Array<int, 2>{3, 5}.data(); }
Insight:
Console: