this post was submitted on 17 Aug 2023
2 points (100.0% liked)

C++

1779 readers
5 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
 

This one was quite a struggle, thought I'd share for the C++ programmers here.

I have a use case where for many function templates I have to instantiate them for a bunch of different parameter types, e.g. unary, binary and ternary functions where each argument can be one of 9 different types, giving 9, 9^2 = 81 or 9^3 = 729 instantiations of each function. Clearly I don't want to write those out as explicit template instantiations, and using macros is error prone too.

I've found this approach with std::variant and std::visit to be useful. Would appreciate any insight on edge cases where this may not work, or other suggested approaches.

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here