Article View: comp.std.c++
Article #3470Namespace extension
From: Igor Boukanov
Date: Fri, 16 Feb 1996 17:06
Date: Fri, 16 Feb 1996 17:06
77 lines
3052 bytes
3052 bytes
Of cause, probably my proposal is of time, but namespaces are quite
new C++ feature, and only now I realize how to make it more flexible...
So I suggest to let template namespaces. In this case it will be possible
to write something like this:
// declaration
template<class T> namespace containers {
class simple_vector {
private:
T* data;
unsigned count;
public:
simple_vector(unsigned acount);
T& operator[](unsigned i);
.. // other methods
};
class simple_list{
... // data members and methods
};
}
...
//implementations
template<class T> namespace containers {
simple_vector::simple_vector(unsigned acount) {
count = acount;
data = new T[acount];
}
T* simple_vector::operator[](unsigned i) { return data[i]; }
... // methods for simple_list;
}
And now how to use it:
void example_of_using_1(){
containers<int>::simple_vector v(10);
containers<float>::simple_list v(10);
};
void example_of_using_2(){
using namespace containers<char>;
simple_vector char_vector(100);
};
I think there are at least next reasons to introduce this extension.
1. It can make declarations and implementations of template libraries much
more clear because one does not need to write template keyword and something
like <T> everywhere. (Just look at the example: I used "template" word only
twice and I never used <T> inside containers namespace.)
2. It will be much more easy to instant such library for particular
template parameters.
(For a example, containers from example can be instanted by single line:
template namespace containers<bool>;
instead of such line for each template class.)
3. It makes C++ easy to study, because somebody will have to know only
the general idea about templates and how to apply them to any C++ elements
(function, class, namespase,...).
So, what do you think about this?
--
Regards, Igor Boukanov (igor.boukanov@fi.uib.no).
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID:
<4g2aj2$bko@ugress.uib.no>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: boukanov@kvark.fi.uib.no (Igor Boukanov) Newsgroups: comp.std.c++ Subject: Namespace extension Date: 16 Feb 1996 09:06:50 PST Organization: Fysisk institutt, Universitetet i Bergen Approved: austern@isolde.mti.sgi.com Message-ID: <4g2aj2$bko@ugress.uib.no> NNTP-Posting-Host: isolde.mti.sgi.com Summary: I propose to let template nemespaces. Keywords: C++, namespace, template X-Original-Date: 16 Feb 1996 16:15:30 GMT X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMSS5uEy4NqrwXLNJAQFqTwIAjZn7b/50m+wrJg6bvvH3LEDdtqtlNHe3 Z2RfIlngApPCE5CLASSgHmS7Vkzwyq6QZjTidte6CApaarUvQzCRMw== =ZeXn Originator: austern@isolde.mti.sgi.com