Re: Explicitly specializing std::min() on VC++ 2005 Express Edition



"Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx> schrieb im Newsbeitrag
news:%23tlRhSWjHHA.4772@xxxxxxxxxxxxxxxxxxxxxxx

You have your answer, but just to make things worse, what you are doing is
illegal anyway - you aren't allowed to specialize std function templates
unless the specialization involves a user-declared name (e.g. you can
specialize them for your own types, but not for built-in or standard
library types).

In practice, whether you care about this is up to you, but it is possible
a library might include its own explicit specializations or explicit
instantiations for such specializations, thus rendering your own explicit
specialization either undefined behaviour or a compiler error.

But what if I want to specialize a template function that I wrote myself? I
might have template function such as:

template <class T> inline
const T& minimum( const T& a, const T& b )
{ return a < b ? a : b; }

Then how do I specialize it in such a way that I can pass C-style strings? I
guess the answer is to overload the function instead of specializing it...
By the way, I found an interesting article on the topic of overloading vs.
specialization here: http://www.gotw.ca/publications/mill17.htm

--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers


.



Relevant Pages

  • Re: Is code generated in this template situation?
    ... >> If foo is never called, this template will never be instantiated. ... That's what an explicit instantiation *does* - it explicitly directs the ... compile the result of this substitution into binary executable code (which ...
    (comp.lang.cpp)
  • Re: definition of template static default-constructed data members impossible?
    ... >> The above is a defenition, unlike the uninitialized explicit ... > class of data members. ... class template foo< S> is instantiated with. ...
    (comp.lang.cpp)
  • Re: Is code generated in this template situation?
    ... > If foo is never called, this template will never be instantiated. ... > Code will be generated for this explicit instantiation whether it is ever ...
    (comp.lang.cpp)
  • Re: specialization of member functions of class templates
    ... > From what I've read in several places, it seems that explicit ... > of member functions of class templates is allowed, ... before you attempt to define the member. ... the same partial specialisation of the enclosing template to exist. ...
    (comp.lang.cpp)
  • Re: Partial Template Specialization
    ... > I have a problem with partial template specialization. ... > below I have a template struct Music with one method, play, ... This is explicit specialization. ... 'Music' and still have method 'play' in it, ...
    (comp.lang.cpp)

Loading