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
None
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
// Our template function: it just asserts that the types satisfy our desired properties. template <class IndexType, class DataType, class EntityType> void my_func() { // .... } // Some dummy classes struct MyEntity {}; struct OtherEntity {}; // A simple template for holding a list of types. template<typename... Ts> struct TypeList {}; // Define our type lists. using IndexTypes = TypeList<int, unsigned>; // e.g., int and unsigned using DataTypes = TypeList<double, float>; // e.g., double and float using EntityTypes = TypeList<MyEntity, OtherEntity>; // e.g., two entity classes // A helper that forces instantiation by taking the function's address. template<typename IndexType, typename DataType, typename EntityType> inline constexpr void instantiate_one() noexcept { [[maybe_unused]] auto ptr = &my_func<IndexType, DataType, EntityType>; } // Combined function using template lambdas to instantiate all combinations template<typename... Is, typename... Ds, typename... Es> constexpr void instantiate_all_combos(TypeList<Is...>, TypeList<Ds...>, TypeList<Es...>) noexcept { // Use C++20 template lambdas with immediate invocation for each type level (([&]<typename I>() { (([&]<typename D>() { (instantiate_one<I, D, Es>(), ...); }.template operator()<Ds>()), ...); }.template operator()<Is>()), ...); } int main() { // This call forces instantiation of my_func for every combination in our type lists. instantiate_all_combos(IndexTypes{}, DataTypes{}, EntityTypes{}); }
Insight:
Console: