Re:A quick primer on type traits in modern C++
by gpderetta on Saturday February 29, 2020 @10:30AM
(#22451010)
You do not switch on types, you switch on groups of tuoes having certain properties. It is not a new thing this sort of thing has been doable for the last 20 years in a form or another.
Re:A quick primer on type traits in modern C++
by ahartmetz on Saturday February 29, 2020 @10:21AM
(#22450964)
I have an example for you.
A serialization library that supports container classes. It has a generic way to fill lists (vectors), but not all list containers support resize and default-initialize new elements. So somewhere inside a generic template function there is a switch to use or replicate that function.
Re:A quick primer on type traits in modern C++
by gumby on Saturday February 29, 2020 @01:27PM
(#22452054)
Think of it the other way around: there’s a generic method/template, but the developer has a special implementation for a specific case. The compiler already does this for things like memmove() that is properly aligned and sized; this allows user code to cleanly do the same thing.
But what do I know, I haven't done C++ for about 5 years and was never that into it.