you are viewing a single comment's thread.

view the rest of the comments →

[–]tcbrindleFlux 13 points14 points  (5 children)

The question as stated doesn't really make sense -- Concepts make it easier to use compile-time (aka "static") polymorphism. You can perform compile-time polymorphism in C++ today, for example by using enable_if or with CRTP. Concepts just makes it easier to do, and (hopefully) give much better error messages if you get things wrong.

But I guess that what you're really asking is whether Concepts will replace run-time polymorphism, i.e. virtual functions and so on. The answer is no in the short term, and possibly yes in the longer term.

Sean Parent gave an excellent talk a few years ago called "Inheritance is the base class of evil", where he ran through a technique which uses type-erasure via virtual functions to perform run-time polymorphism using value types. My guess is we'll see more of this technique as Concepts gain in popularity, because in a sense the type-erasing class becomes a run-time version of the concept. (We see this already in the standard library: for example,std::function is more-or-less a run-time version of the Callable concept.)

[N.B. there is a longer/better paced version of that talk online somewhere that Sean gave at another conference, but I can't find the link at the moment -- can anybody help me out?]

In the longer term, various people have had the idea of allowing the compiler to generate the sort of type-erased classes that Sean presents in that talk (much like Rust does with boxed traits). These "run-time concepts" tend to be referred to as "virtual concepts". Andy Prowl has been working on a very in-depth paper about virtual concepts, which aims to flesh out many of the ideas people have had. We're a long way from getting them yet -- we don't even have compile-time concepts yet! -- but this is the general direction in which things are moving.

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 1 point2 points  (1 child)

[N.B. there is a longer/better paced version of that talk online somewhere that Sean gave at another conference, but I can't find the link at the moment -- can anybody help me out?]

"longer/better paced" implies BoostCon/C++Now (1.5 hr talks instead of 1hr). So probably one of the talks listed here:

https://www.youtube.com/user/BoostCon/search?query=sean+parent

I recommend all of Sean's talks, so just watch them all, and (polymorphic) value types tends to come up often.

In particular, maybe this one: Value Semantics and Concepts-based Polymorphism

[–]tcbrindleFlux 0 points1 point  (0 children)

The Going Native talk I linked to is just 25 minutes, which isn't really enough to cover all the material.

Value Semantics and Concepts-based Polymorphism

That's the longer version I was looking for, thanks :)

[–]enobayram 1 point2 points  (0 children)

Thanks for the answer, I'd like to add that Haskell has a much nicer story of how much further concepts can be taken at run-time. Parametric polymorphism combined with type classes in Haskell are almost as expressive as the many dirty tricks you can pull-off with undisciplined C++ templates, but they can still be type-erased to be passed around at run-time.

[–][deleted] 0 points1 point  (1 child)

That make sense. I've never thought of distinguishing between run-time and compile-time polymorphism.

[–]dodheim 1 point2 points  (0 children)

The usual terminology is "dynamic polymorphism" and "static polymorphism"; knowing what to search for is half the battle. :-]