Specializing template constructors

Specializing template constructors

Post by llewell » Sun, 03 Aug 2003 01:11:39





>> I am not sure if all explicit specializations must start
>> with "template <>" though. An explicit specialization can
>> also be a partial specialization, I guess.

> Pedantically, no, a partial specialisation is never an
> explicit specialisation.  They are different (though closely
> related) things.  So an explicit specialisation will always
> start "template <>" and a partial specialisation will always
> start "template </* arguments */>".  In retrospect, it might
> have been better if explicit specialisations were called
> complete specialisations as this much better describes how
> they are related to partial specialisations.

I think explicit specialisations got their name before partial
    specialisations were devised. Remember, a template instantiation
    is a specialisation - but not an explicit specialisation.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

 
 
 

Specializing template constructors

Post by Jakob Bielin » Sun, 03 Aug 2003 02:12:41



Quote:> Explicit specialisations may only be at namespace scope, not
> at class scope.

    Is this true for non-template classes with member templates as well?

Quote:> >     A (A <int> const&)

> This is not doing what the OP wanted, which was specialise
> for the case where T == int and U was anything.  You
> appear to be trying to specialise for the case where T is
> anything and U == A<int>.

    Right, because he said he wanted to "specialize [the] member template
constructor for A<int>", which is where I misunderstood his post. So if I
understood you correctly, if he wanted T to be anything and U = A <int>,
then there would be no solution, because explicit specialisations or member
templates of a template class are never (regardless of which scope they are
defined in) allowed.

regards
--
jb

(replace y with x if you want to reply by e-mail)

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

 
 
 

Specializing template constructors

Post by Andy Sawye » Mon, 04 Aug 2003 07:19:58



 on 31 Jul 2003 14:00:06 -0400,

Quote:> With the caveat that you are in undefined land because you are deriving
> from a class that does not have a virtual dtor. You also have a derived
> to base conversion problem waiting to bite when you least expect it.

Deriving from a class without a virtual destructor does NOT put you in
"undefined land". The behaviour is only undefined in the case where you
(or somebody else) attempt to delete the object through a base class
pointer.

Regards,
 Andy S
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]