Topic: Partial Ordering of Template Specializations
Author: fwai@armltd.co.uk (Francis Wai)
Date: 1996/08/15 Raw View
100611.1330@compuserve.com (Jean-Louis Leroy) writes:
>I'm have a lot of trouble making sense of DWP 14.6.2 (partial ordering
>of function template specializations) and DWP 14.10.6 (partial
>ordering of class template specializations). Probably because these
>clauses are written in terms of 'how' instead of 'what'.
I'm sure you are not the only one. ;-)
>Partial ordering of function template specializations: given two
>function templates T1 and T2, T1 is more specialized than T2 iff the
>set of all the functions that can be generated from T1 is a proper
>subset of the set of all the functions that can be generated from T2.
You're talking about using the arguments of a call for the generation of
possible instances. I believe the intention is that the compiler should
be able to establish a partial ordering among function templates of the
same name _independently_ of any call. (I'm sticking my neck out.)
Yes, the Draft describes 'how' this can be done. For each such function
template, fake a call to each of the others. The type of each argument
in the call is the type of the corresponding formal parameter of itself.
Type deduction occurs to check the validity of the call as it would in the
normal case. The result, if succeeded, of the type deduction is the signature
of the template function to be generated from the one picked.
If this signature is "identical" (for some definition of identical) to the
one the compiler started with, then the one started with is at least as
specialised as the one picked.
A function template is considered more specialised than another, iff it
is at least as specialised than the other, but not the other way round.
If type deduction fails, then no comparison can be made. Partial
ordering occurs in case when a pair cannot be compared.
Take for example,
template <class T> void f(const T*); // -- (1)
template <class T> void f(T*); // -- (2)
Started with (1), type deduction makes 'T' in (2) to become 'const T'.
Hence (1) is at least as specialised as (2).
Started with (2), type deduction makes 'T' in (1) to become 'T' and
the resultant signature is that of (1) which is not "identical" to
that of (2) because of the 'const'. Hence (2) is not at least as
specialised as (1).
Hence (1) is considered more specialised than (2).
Partial ordering of class template specialisations is largely
based on that for function templates.
Any comments?
--Francis
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: 100611.1330@compuserve.com (Jean-Louis Leroy)
Date: 1996/08/14 Raw View
Hello,
I'm have a lot of trouble making sense of DWP 14.6.2 (partial ordering
of function template specializations) and DWP 14.10.6 (partial
ordering of class template specializations). Probably because these
clauses are written in terms of 'how' instead of 'what'.
I tried to figure out sensible rules and I've come up with these:
Partial ordering of function template specializations: given two
function templates T1 and T2, T1 is more specialized than T2 iff the
set of all the functions that can be generated from T1 is a proper
subset of the set of all the functions that can be generated from T2.
Partial ordering of class template specializations: given two class
templates T1 and T2, T1 is more specialized than T2 iff the set of all
the classes that can be generated from T1 is a proper subset of the
set of all the classes that can be generated from T2.
Are these two statements indeed equivalent to the respective DWP
clauses? TIA...
jl :)
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]