News for hackers. Stuff that matters.
Re:A quick primer on type traits in modern C++ by Nursie on Saturday February 29, 2020 @09:44AM (#22450789)
It just looks kinda wrong to me - If your generic template has to switch on what type it's been passed, surely you've made it too generic somewhere? Adding back conditional compilation or execution afterwards strikes me as the same sort of code-smell as checking if something is an instance of a given class before then casting it and calling a member - you've lost information and using some sort of reflection to get it back looks like poorly thought out code. Sure, there are times when you more or less have to, but you ought to try to avoid them.

But what do I know, I haven't done C++ for about 5 years and was never that into it.

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.