Topic: Proposal for a <stdfwd> header
Author: rtw@freenet.REMOVE.co.uk (Rob Williscroft)
Date: Wed, 24 Mar 2004 20:31:35 +0000 (UTC) Raw View
Gennaro Prota wrote in news:dqpl50t17gq852tc03qgpohk143k2spim4@4ax.com:
> The problems that still exist are that a) adding declarations of
> standard classes to namespace std results in undefined behavior if the
> declarations do not depend on a user-defined name with external
> linkage b) default arguments for template parameters cannot be given
> twice in the same scope.
>
But we could still forward declare:
namespace std
{
template < typename T, typename A > class vector;
}
Or do you think this is case (a) adding a declaration to namespace std ?
Its clearly a declaration in namespace std. I'm just not sure wether
anything is being "added" ?
Rob.
--
http://www.victim-prime.dsl.pipex.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: ljestrada@hotmail.com (Javier Estrada)
Date: Mon, 15 Mar 2004 21:09:35 +0000 (UTC) Raw View
It seems natural that if there is a <iosfwd> to forward declare the I/O
related classes, there should be a header for the classes contained in the
std namespace.
In the trenches, often times I come across classes that can be simply
defined in terms of references and pointers to other classes. An example is
defining interfaces or "protocol classes." Granted, with a small project,
using an <stdfwd> header does not provide a big advantage, but I deal with
500+ files in a framework...
I believe that the rationale is so simple that I even feel lazy about
explaining the benefits, but oh well:
// needlessly including the definition of string (or basic_string) and
vector
#include <string>
#include <vector>
class ISeek{
public:
virtual void seek_knowledge(const std::string& token) = 0;
virtual void seek_advice(const std::vector<std::string>& advisers) = 0;
};
// using the proposed header...
#include <stdfwd>
class ISeek{
public:
virtual void seek_knowledge(const std::string& token) = 0;
virtual void seek_advice(const std::vector<std::string>& advisers) = 0;
};
Please ready your darts and fire at will. I'd like to know if there is
enough support that it could fly in a proposal to the std committee.
Javier
jestrada at developeer dot 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: jorgeri@rochester.rr.com (Jorge Rivera)
Date: Wed, 17 Mar 2004 00:50:29 +0000 (UTC) Raw View
> // using the proposed header...
> #include <stdfwd>
>
> class ISeek{
> public:
> virtual void seek_knowledge(const std::string& token) = 0;
> virtual void seek_advice(const std::vector<std::string>& advisers) = 0;
> };
>
I know nothing of any standard limitation. But I think forward
declaring templated classes is not trivial.
This could be my own question, but is there an effective way of
forward-declaring templated functions? If not, does it make any sense
in allowing it?
JLR
---
[ 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: please_use_webform@vecerina.com ("Ivan Vecerina")
Date: Fri, 19 Mar 2004 01:12:38 +0000 (UTC) Raw View
"Jorge Rivera" <jorgeri@rochester.rr.com> wrote in message
news:Fqt5c.20332$Fh4.9967@twister.nyroc.rr.com...
> > // using the proposed header...
> > #include <stdfwd>
> >
> > class ISeek{
> > public:
> > virtual void seek_knowledge(const std::string& token) = 0;
> > virtual void seek_advice(const std::vector<std::string>& advisers) =
0;
> > };
>
> I know nothing of any standard limitation. But I think forward
> declaring templated classes is not trivial.
Actually, it is mostly the same as for non-template classes:
you omit the body of the class definition, and that's it.
> This could be my own question, but is there an effective way of
> forward-declaring templated functions? If not, does it make any sense
> in allowing it?
It is easy to do, but it cannot be done for standard classes,
because mere users cannot make all required assumptions about
the default parameters of standard templates (or even IIRC
about the potential additional parameters).
Some implementations of the standard library have been providing
a forward-defined version of <string> for years now.
I agree with Javier that this can be a helpful feature
for large projects.
Regards
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
---
[ 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: bop@gmb.dk ("Bo Persson")
Date: Fri, 19 Mar 2004 19:47:51 +0000 (UTC) Raw View
""Ivan Vecerina"" <please_use_webform@vecerina.com> skrev i meddelandet
news:c3bni4$f5a$1@newshispeed.ch...
> "Jorge Rivera" <jorgeri@rochester.rr.com> wrote in message
> news:Fqt5c.20332$Fh4.9967@twister.nyroc.rr.com...
> > > // using the proposed header...
> > > #include <stdfwd>
> > >
> > > class ISeek{
> > > public:
> > > virtual void seek_knowledge(const std::string& token) = 0;
> > > virtual void seek_advice(const std::vector<std::string>& advisers) =
> 0;
> > > };
> >
> > I know nothing of any standard limitation. But I think forward
> > declaring templated classes is not trivial.
>
> Actually, it is mostly the same as for non-template classes:
> you omit the body of the class definition, and that's it.
>
> > This could be my own question, but is there an effective way of
> > forward-declaring templated functions? If not, does it make any sense
> > in allowing it?
>
> It is easy to do, but it cannot be done for standard classes,
> because mere users cannot make all required assumptions about
> the default parameters of standard templates (or even IIRC
> about the potential additional parameters).
One problem is that it is not allowed to redeclare the default template
parameters. This means that if you forward declare the templates, the
regular headers must somehow include the forward declarations and then not
declare the parameter values themselves.
Hard to fix for a user. :-)
Bo Persson
---
[ 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: Nicola.Musatti@ObjectWay.it (Nicola Musatti)
Date: Fri, 19 Mar 2004 20:01:20 +0000 (UTC) Raw View
I second this proposal. On some platforms the inclusion of one single
standard header results in the compilation of several thousand lines
of code.
While precompiled heeaders alleviate the problem, they worsen the
dependencies between one's project and external includes, which by the
way results in an increase of dependency tracking times for make-like
tools.
Cheers,
Nicola Musatti
---
[ 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: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Wed, 24 Mar 2004 09:14:18 +0000 (UTC) Raw View
On Fri, 19 Mar 2004 01:12:38 +0000 (UTC),
please_use_webform@vecerina.com ("Ivan Vecerina") wrote:
>It is easy to do, but it cannot be done for standard classes,
>because mere users cannot make all required assumptions about
>the default parameters of standard templates (or even IIRC
>about the potential additional parameters).
There was a school of thought that believed implementations can add
defaulted parameters (as SGI and its derivations used to do for
std::bitset). But the committee clarified that this is illegal:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-closed.html#94
The problems that still exist are that a) adding declarations of
standard classes to namespace std results in undefined behavior if the
declarations do not depend on a user-defined name with external
linkage b) default arguments for template parameters cannot be given
twice in the same scope.
--
Genny.
---
[ 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 ]