February 2005
Beginner to intermediate
272 pages
4h 53m
English
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 ...
Read now
Unlock full access