O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item 53. Embedded Type Information

How do we know the type of a container’s elements?

template <typename T>class Seq {    //...};

At first, this may not seem to be a problem. The element type of Seq<std::string> is std::string, right? Not necessarily. There’s nothing to prevent the implementation of our (nonstandard) sequence container from making the element type const T, T *, or a “smart pointer” to a T. (A particularly weird container could simply ignore the template parameter and always set the element type to void *!) But vagary of implementation is not the only reason we may not be able to determine the element type of our container. We often write generic code in which that information is simply not available.

In the process generic ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required