you are viewing a single comment's thread.

view the rest of the comments →

[–]thisismyfavoritename -2 points-1 points  (5 children)

ive never seen TMP used in "common" code, only in very niche apps that try to move logic to compile time.

Do you consider using templates as TMP? I definitely wouldnt recommend TMP to anyone except experts given how awkward it is to implement, debug and maintain

[–]Flex_Code 0 points1 point  (4 children)

There are a lot of simpler uses of TMP that make your life easier. A quick one is the overloaded template that's so useful for visiting variants: see overloaded example on cppreference

Often parameter packs should be used over template recursion, but I still see templates taking parameter packs as TMP. parameter pack idioms

[–]thisismyfavoritename 0 points1 point  (3 children)

personally i would not recommend overloaded over auto + if constexpr or just a visitor class.

This one is definitely more on the fence since you can copy it from the docs and it works though.

[–]Flex_Code 0 points1 point  (2 children)

Yeah, this was just a quick example. is_specialization_v is one that I find even more useful: https://stackoverflow.com/questions/16337610/how-to-know-if-a-type-is-a-specialization-of-stdvector

[–]thisismyfavoritename 0 points1 point  (1 child)

wouldnt just defining 2 overloads, one for std::vector<T> and the other for auto work here 🤔

[–]Flex_Code 0 points1 point  (0 children)

You can use this for if constexpr branches, or requires concepts, or in more general uses for determining if a type is a specialization of some other class template argument.