Topic: Explicit instantiation in different namespace
Author: ghost@cs.msu.su (Vladimir Prus)
Date: Fri, 19 Mar 2004 01:12:48 +0000 (UTC) Raw View
I have a question about explicit instantiation. Is it possible to declare
class template or function template in one namespace and explicitly
instantiate it in another namespace?
Consider the following example:
namespace serialization {
=9A=9A=9A=9Atemplate<class=9AT>
=9A=9A=9A=9Aclass=9Ahelper=9A{};
=9A=9A=9A=9A
=9A=9A=9A=9Atemplate<class=9AT,=9Aclass=9ASeq>
=9A=9A=9A=9Avoid
=9A=9A=9A=9Aboost_template_instantiate(T=9A&,Seq=9A&)=9A{}
}
namespace X
{
=9A=9A=9A=9Aclass=9AC=9A{};
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A
=9A=9A=9A=9Atemplate
=9A=9A=9A=9Avoid
=9A=9A=9A=9Aserialization::boost_template_instantiate<>(X::C=9A&,=9Aint=9A=
&);
=9A=9A=9A=9A
=9A=9A=9A=9Atemplate
=9A=9A=9A=9Aclass=9Aserialization::helper<int>;
}
Both gcc 3.3 and online Comeau reject the first instantiation. The error
message say explicit instantiation can't be placed here. OTOH, explicit
instantiation of the class works OK. I can't find anything in the standar=
d
that would explain this error.=20
So, it it just the same bug in two compilers, or I've missed something?
Thanks in advance,
Volodya
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rogero@howzatt.demon.co.uk ("Roger Orr")
Date: Wed, 24 Mar 2004 02:05:00 +0000 (UTC) Raw View
(to mods: this is a repost - I got a notification from my first post but
nothing further...)
>"Vladimir Prus" <ghost@cs.msu.su> wrote in message
news:u5boi1-7te.ln1@zigzag.lvk.cs.msu.su...
>I have a question about explicit instantiation. Is it possible to declare
>class template or function template in one namespace and explicitly
>instantiate it in another namespace?
I believe this should be valid - see Explicit instantiation 14.7.2p5
"An explicit instantiation of a class or function template specialization is
placed in the namespace in which
the template is defined."
(MSVC 7 compiles your example, FWIW)
Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dag_henriksson@hotmail.com ("Dag Henriksson")
Date: Wed, 24 Mar 2004 09:14:04 +0000 (UTC) Raw View
"Vladimir Prus" <ghost@cs.msu.su> skrev i meddelandet
news:u5boi1-7te.ln1@zigzag.lvk.cs.msu.su...
> I have a question about explicit instantiation. Is it possible to declare
> class template or function template in one namespace and explicitly
> instantiate it in another namespace?
I think this is covered in
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#275
Proposed resolution : "An explicit instantiation shall appear in an
enclosing namespace of its template."
--
Dag Henriksson
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rogero@howzatt.demon.co.uk ("Roger Orr")
Date: Wed, 24 Mar 2004 09:14:34 +0000 (UTC) Raw View
>"Vladimir Prus" <ghost@cs.msu.su> wrote in message
news:u5boi1-7te.ln1@zigzag.lvk.cs.msu.su...
>I have a question about explicit instantiation. Is it possible to declare
>class template or function template in one namespace and explicitly
>instantiate it in another namespace?
I believe this should be valid - see Explicit instantiation 14.7.2p5
"An explicit instantiation of a class or function template specialization is
placed in the namespace in which
the template is defined."
(MSVC 7 compiles your example, FWIW)
Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]