lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] C++11 extern template (was: Delegating ctor uncalled for?)


From: Vadim Zeitlin
Subject: Re: [lmi] C++11 extern template (was: Delegating ctor uncalled for?)
Date: Wed, 8 Feb 2017 17:39:15 +0100

On Wed, 8 Feb 2017 11:29:38 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-02-07 14:37, Vadim Zeitlin wrote:
...
GC> >  BTW, this would, again, be irrelevant anyhow if you follow my idea of
GC> > using a private template ctor or a function, but I thought to use another
GC> > C++ feature I had never used before, even though it appeared in C++11,
GC> > called "explicit instantiation declarations" a.k.a. "extern templates". I
GC> > believed I could prevent implicit instantiation from compiling in this 
way,
GC> > but it looks like I misunderstood how this worked because the code using
GC> > InputSequence ctor from std::vector<bool> still compiled just fine -- even
GC> > though it failed to link, of course. Now I wonder what exactly extern
GC> > templates are useful for...
GC> 
GC> I actually thought of that when I was writing the patch we're discussing
GC> here, so I looked it up...and came away with the same question. I just
GC> don't see any reason why I'd want to use them.

 Just to get this out of the way: I understand this now, after reading
http://stackoverflow.com/a/8131212/15275 (which is wrong, BTW, as pointed
out in the comment by Johannes Schaub, but this doesn't diminish its
pedagogical value). It's really just an optimization of compile-time which
tells the compiler to not bother implicitly instantiating this particular
template instance, but doesn't say anything at all about instantiating (and
especially refusing to instantiate) any other instances of it. So it was
definitely a mistake to think about it as I did.

 But IMHO there is still something wrong with the explanation at
http://en.cppreference.com/w/cpp/language/class_template if it create the
same misunderstanding for both of us, so I'll think about proposing to
change it to be more clear.

 Regards,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]