13.12 Overloaded Class Templates

Ru-Brd

It is entirely possible to imagine that class templates could be overloaded on their template parameters. For example, one can imagine the following:

 template <typename T1>  class Tuple {  // singleton    };  template <typename T1, typename T2>  class Tuple {  // pair    };  template <typename T1, typename T2, typename T3>  class Tuple {  // three-element tuple    }; 

In the next section we discuss an application of such overloading.

The overloading isn't necessarily restricted to the number of template parameters (such overloading could be emulated using partial specialization as is done for FunctionPtr in Chapter 22). The kind of parameters can be varied too:

 template <typename T1, typename T2>  class Pair {  // pair of fields    };  template <int I1, int I2>  class Pair {  // pair of constant integer values    }; 

Although this idea has been discussed informally by some language designers, it has not yet been formally presented to the C++ standardization committee.

Ru-Brd


C++ Templates
C++ Templates: The Complete Guide
ISBN: 0201734842
EAN: 2147483647
Year: 2002
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net