This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Vector Extensions in GCC


"Joseph S. Myers" <jsm28@cam.ac.uk> writes:

| On Thu, 12 Jul 2001, Mark Mitchell wrote:
| 
| >   template <typename T> T acos (T);
| >   template <> double acos(double d) { return cos (d); }
| >   template <> float acos(float f) { return cosf (f); }
| >   template <> long double acos(long double l) { return cosl (l); }
| 
| You then need to handle integer types, and complex types, and functions
| with more than one argument have correspondingly larger collections of
| specializations.

That is no more work you would have to do with overloading.
Furthermore, with just overloading you will have to duplicate codes
where templates just let you write it once.

When we have to invent extensions to solve some problems, we need to
have a larger view and see what mechanisms closely related languages
provide to solve the same set of problems and where they are heading.
In this particular case, a subset of C++ template is sufficiently
orthogonal to be added as pure extension to C, and it solves a larger
set of problems than sole overloading does.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]