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
Workshop: Safe and Efficient C++ for Embedded Environments
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <stddef.h> #include <utility> using namespace std; constexpr int count_bits(unsigned char value) { if (value == 0) { return 0; } else { return (value & 1) + count_bits(value >> 1); } } template <size_t... V> struct bit_count_t { unsigned char count[sizeof...(V)] = { static_cast<unsigned char>( count_bits(V))...}; }; template <size_t... V> constexpr bit_count_t<V...> get_bit_count(index_sequence<V...>) { return bit_count_t<V...>(); } auto bit_count = get_bit_count( make_index_sequence<4>());
Insight:
Console: