C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can "export" be used with explicit specialization?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Hubert Holin
Guest





PostPosted: Fri Oct 21, 2005 2:47 pm    Post subject: Can "export" be used with explicit specialization? Reply with quote



Somewhere in the E.U., le 21/10/2005

Bonjour

Reading 14.7.3, it is not clear to me if it is possible to export an
explicit specialization of a non-exported template function.

In the example below, "grabuge.hpp" declares a template and two
explicit specialization, one of which is defined (and exported) in
the file "grabuge.cpp" (and the second of which is never defined).

Is the example legal or not? Since the optional "export" keyword is
not listed in the grammar detailing explicit specialization, I would
guess the program is perhaps, after all, not legal. In that case, it
would appear to be a deficiency of the standard. The closest thing I
could find to that topic is clause 8, which does not seem to be
entirely relevant.

Merci

Hubert Holin


8>< ------------ main.cpp ------------ ><8


#include "grabuge.hpp"



int main (int argc, char * const argv[])
{
::std::cout << "There are " << argc << " arguments, with values:
" << ::std::endl;

for (int idx = 0; idx < argc; ++idx)
{
switch (idx)
{
case 0:

::std::cout << grabuge<0> << argv[idx] << ::std::endl;

break;

default:

::std::cout << grabuge<-1> << argv[idx] << ::std::endl;

break;
}
}

return 0;
}

8>< --------------------------------- ><8

8>< ---------- grabuge.hpp----------- ><8

#include

template<int selector>
::std::ostream & grabuge(::std::ostream & s)
{
return(s);
}

template<>
::std::ostream & grabuge<0>(::std::ostream & s);

template<>
::std::ostream & grabuge<1>(::std::ostream & s); // actually
not defined!

8>< --------------------------------- ><8

8>< ---------- grabuge.cpp----------- ><8


#include "grabuge.hpp"



export template<>
::std::ostream & grabuge<0>(::std::ostream & s)
{
return(s << "The 0th argument, by tradition, is: ");
}


8>< --------------------------------- ><8

---
[ 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 ]

Back to top
google@vandevoorde.com
Guest





PostPosted: Sat Oct 22, 2005 6:40 pm    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote




Hubert Holin wrote:
Quote:
Somewhere in the E.U., le 21/10/2005

Bonjour

Reading 14.7.3, it is not clear to me if it is possible to export an
explicit specialization of a non-exported template function.

No, the grammar doesn't allow it. Only the grammar rule in 14/1
allows for the keyword "export".

Quote:
In the example below, "grabuge.hpp" declares a template and two
explicit specialization, one of which is defined (and exported) in
the file "grabuge.cpp" (and the second of which is never defined).

Is the example legal or not? Since the optional "export" keyword is
not listed in the grammar detailing explicit specialization, I would
guess the program is perhaps, after all, not legal.

Right.

Quote:
In that case, it
would appear to be a deficiency of the standard.

Can you elaborate? Why is it a deficiency?

Daveed

---
[ 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 ]


Back to top
Hubert Holin
Guest





PostPosted: Mon Oct 24, 2005 4:25 pm    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote



Somewhere in the E.U., le 24/10/2005

Bonjour

In article <1129933108.040492.203720 (AT) z14g2000cwz (DOT) googlegroups.com>,
[email]google (AT) vandevoorde (DOT) com[/email] wrote:

Quote:
Hubert Holin wrote:
Somewhere in the E.U., le 21/10/2005

Bonjour

Reading 14.7.3, it is not clear to me if it is possible to
export an
explicit specialization of a non-exported template function.

[SNIP]

Quote:
Is the example legal or not? Since the optional "export" keyword is
not listed in the grammar detailing explicit specialization, I
would
guess the program is perhaps, after all, not legal.

Right.

In that case, it
would appear to be a deficiency of the standard.

Can you elaborate? Why is it a deficiency?

Daveed


My belief that this represents a deficiency stems from the
assumption that the "export" keyword exists to provide some amount of
code modularity (in addition to potential code hiding): the user of
the template need only know the methods of the template, not their
implementation.

I therefore find it odd that one can export general methods
(the unspecialized template), but not specific ones (the explicitly
specialized template).

Certainly, the compiler has to be aware that these explicit
instantiations exist, but I fail to see how this differs from the
fact it has to be aware that the exported (unspecialized) template
exists.

What am I missing?

Merci

Hubert Holin


---
[ 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 ]


Back to top
Ben Hutchings
Guest





PostPosted: Tue Oct 25, 2005 1:51 am    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote

Hubert Holin <Hubert.Holin (AT) lmd (DOT) polytechnique.fr> wrote:
<snip>
Quote:
My belief that this represents a deficiency stems from the
assumption that the "export" keyword exists to provide some amount of
code modularity (in addition to potential code hiding): the user of
the template need only know the methods of the template, not their
implementation.

I therefore find it odd that one can export general methods
(the unspecialized template), but not specific ones (the explicitly
specialized template).

Certainly, the compiler has to be aware that these explicit
instantiations exist, but I fail to see how this differs from the
fact it has to be aware that the exported (unspecialized) template
exists.

What am I missing?

In practice, "export" causes the compiler to generate information
about a template definition in or alongside the object file that it
produces, so that the template can be implicitly instantiated between
the normal compilation process and linking (or by the linker calling
the compiler when it recognises an undefined symbol as being
satisfiable by such instantiation). I assume that the standard
committee did not intend this to be done by default because it would
bloat object files generated from the compilation of source files that
use the existing model of including template definitions in every
translation unit that requires them, and perhaps also because it
could effectively reveal proprietary source code.

For full specialisations, this issue does not arise. Linking to a
full specialisation of a function template works much like linking to
an ordinary function; callers only need the function's declaration and
(at link time) its object code.

--
Ben Hutchings
For every complex problem
there is a solution that is simple, neat, and wrong.

---
[ 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 ]


Back to top
google@vandevoorde.com
Guest





PostPosted: Tue Oct 25, 2005 3:24 am    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote


Hubert Holin wrote:
Quote:
Somewhere in the E.U., le 24/10/2005

Bonjour

In article <1129933108.040492.203720 (AT) z14g2000cwz (DOT) googlegroups.com>,
[email]google (AT) vandevoorde (DOT) com[/email] wrote:

Hubert Holin wrote:
Somewhere in the E.U., le 21/10/2005

Bonjour

Reading 14.7.3, it is not clear to me if it is possible to
export an
explicit specialization of a non-exported template function.

[SNIP]

Is the example legal or not? Since the optional "export" keyword is
not listed in the grammar detailing explicit specialization, I
would
guess the program is perhaps, after all, not legal.

Right.

In that case, it
would appear to be a deficiency of the standard.

Can you elaborate? Why is it a deficiency?

Daveed


My belief that this represents a deficiency stems from the
assumption that the "export" keyword exists to provide some amount of
code modularity (in addition to potential code hiding): the user of
the template need only know the methods of the template, not their
implementation.

I therefore find it odd that one can export general methods
(the unspecialized template), but not specific ones (the explicitly
specialized template).

Certainly, the compiler has to be aware that these explicit
instantiations exist, but I fail to see how this differs from the
fact it has to be aware that the exported (unspecialized) template
exists.

What am I missing?

Explicit template specializations are not templates and can therefore
be separately compiled (or not) in the same way as their
nonparameterized
counterparts. For example:

// File f.hpp:
template<typename T> void f() {}
template<> void f<int>(); // Declaration only

// File f.cpp:
#include "f.hpp"

template<> void f<int>() {}

The original intent was that template be separable in the exact same
way, with no special new keyword required (although you would have
been able to say "extern" as you can with ordinary functions and
variables). The original Cfront implementation tried to fake this by
making some assumptions about file organization. However, that
scheme was not standardizable and for a long time the standard was
unclear about template declaration/definition separation. Eventually
a compromise was developed that required separated templates to
be marked with "export". For nontemplates (including explicit
specializations), that was not needed though.

Daveed

---
[ 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 ]


Back to top
Hubert Holin
Guest





PostPosted: Thu Oct 27, 2005 5:20 pm    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote

Somewhere in the E.U., le 27/10/2005

Bonjour

In article <1130181540.805807.160460 (AT) g44g2000cwa (DOT) googlegroups.com>,
[email]google (AT) vandevoorde (DOT) com[/email] wrote:

[explanation of why "export" is not needed for explicit
specialization of templates]

I see now your point. It is therefore not a deficiency in
the standard. Still some wording could be added (as a note,
preferably), so as to explain (as you did) why it is thus and to
prevent others from getting confused.

Merci

Hubert Holin

---
[ 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 ]

Back to top
kanze
Guest





PostPosted: Tue Nov 01, 2005 4:31 am    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote

[email]google (AT) vandevoorde (DOT) com[/email] wrote:
Quote:
Hubert Holin wrote:
Somewhere in the E.U., le 24/10/2005

In article <1129933108.040492.203720 (AT) z14g2000cwz (DOT) googlegroups.com>,
[email]google (AT) vandevoorde (DOT) com[/email] wrote:

Hubert Holin wrote:
Somewhere in the E.U., le 21/10/2005

Reading 14.7.3, it is not clear to me if it is possible
to export an explicit specialization of a non-exported
template function.

[SNIP]

Is the example legal or not? Since the optional
"export" keyword is not listed in the grammar detailing
explicit specialization, I would guess the program is
perhaps, after all, not legal.

Right.

In that case, it would appear to be a deficiency of the
standard.

Can you elaborate? Why is it a deficiency?

My belief that this represents a deficiency stems from the
assumption that the "export" keyword exists to provide some
amount of code modularity (in addition to potential code
hiding): the user of the template need only know the methods
of the template, not their implementation.

I therefore find it odd that one can export general methods
(the unspecialized template), but not specific ones (the
explicitly specialized template).

Certainly, the compiler has to be aware that these explicit
instantiations exist, but I fail to see how this differs
from the fact it has to be aware that the exported
(unspecialized) template exists.

What am I missing?

Explicit template specializations are not templates and can
therefore be separately compiled (or not) in the same way as
their nonparameterized counterparts. For example:

// File f.hpp:
template<typename T> void f() {}
template<> void f<int>(); // Declaration only

// File f.cpp:
#include "f.hpp"

template<> void f<int>() {}

Does this mean that, as with normal functions, providing a
definition in the .hpp file would result in undefined behavior
(supposing that the file was included in more than one
translation unit).

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ 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 ]


Back to top
google@vandevoorde.com
Guest





PostPosted: Wed Nov 02, 2005 3:51 pm    Post subject: Re: Can "export" be used with explicit specialization? Reply with quote


kanze wrote:
Quote:
google (AT) vandevoorde (DOT) com wrote:
[...]
// File f.hpp:
template<typename T> void f() {}
template<> void f<int>(); // Declaration only

// File f.cpp:
#include "f.hpp"

template<> void f<int>() {}

Does this mean that, as with normal functions, providing a
definition in the .hpp file would result in undefined behavior
(supposing that the file was included in more than one
translation unit).

Indeed and it would in practice result in a duplicate symbol
linker error. (Unless, of course, the specialization is an inline
function.)

Daveed

---
[ 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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.