Article View: comp.std.c++
Article #1708Re: Defining members of class T within cla
From: Wil Evers
Date: Thu, 10 Aug 1995 11:58
Date: Thu, 10 Aug 1995 11:58
74 lines
3629 bytes
3629 bytes
In article <40834p$lm3@engnews2.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve
Clamage) writes:
> Adding a module system to C++ would make it generally easier to use,
> particularly for large projects, but would also make it a different
language.
> Stroustrup elected not to go that route in designing and developing C++,
and
> the C++ committee also elected not to go that route.
>
> The committee felt it had more than enough work to do without adding
> another huge pile of work. Figuring out a module system, or some subset
> that would ease separation of interface and implementation, would take
> years of experimentation in addition to all the work that has been done
> and is still being done on the standard. For example, the template rules
> were published in the ARM in 1990. The rules are still being worked on
> as new problems with the definition of templates are discovered.
>
> I'd like to suggest that someone take the time to define and implement
> something like a module system for C++. To gain wide acceptance, it
should
> allow existing C++ source and object code to be integrated into Modular
C++
> (if I may coin the term) without modification, as well as provide the
same C
> compatibility as C++ currently has. When you are done, submit it for the
next
> round of C++ standardization. The timing should be about right.
Because we already have templates, we may be closer to Modular C++ than
some people think. After all, there isn't much of a difference between
template <class T> void swap(T& t1, T& t2)
{ T tmp = t1; t1 = t2; t2 = tmp; }
and
void swap(SomePartiallySeenClass& t1, SomePartiallySeenClass& t2)
{ SomePartiallySeenClass tmp = t1; t1 = t2; t2 = tmp; }
When parsing the first example, the compiler will have to remember swap's
definition in some half-compiled format and fill in the missing
information when swap() is called for a particular type, that is, when T
is fully defined. Note that swap()'s definition may be in one translation
unit and the call to swap() in another.
This is almost exactly what should happen to the second swap() in Modular
C++ when the full definition of SomePartiallyDefinedClass is seen, the
difference being that the second swap() should be instantiated for one
type only.
Actually, it wouldn't surprise me if some programmers are already using
templates to separate interface and implementation, as in:
template <class Details> class DetailsSpecifiedElsewhere {
public :
// whatever needs to go here
...
private :
Details details;
};
Once this definition is seen, all classes and functions instantiating
objects of the DetailsSpecifiedElsewhere class could be expressed as
templates taking an argument to specify what details to use, waiting to
become fully functional when the details are fully defined and stuffed
into some DetailsSpecifiedElsewhere object.
This, of course, would be a gross abuse of the template mechanism. It
suggests that different sets of implementation details for the
DetailsSpecifiedElsewhere class could be used, which is definitely not
what's intended. However, it does suggest that a mechanism to separate
interface and implementation may already be in place.
- Wil
Technical Details
Message-ID:
<1995Aug10.115851.1438@ittpub>Path:
arc1-ca.pugleaf.net!EU.net!sun4nl!ittpub!ittpub!nntpReferences:
<40834p$lm3@engnews2.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!EU.net!sun4nl!ittpub!ittpub!nntp Newsgroups: comp.std.c++ Subject: Re: Defining members of class T within cla Message-ID: <1995Aug10.115851.1438@ittpub> From: wil@ittpub.nl (Wil Evers) Date: 10 Aug 95 11:58:51 WET References: <40834p$lm3@engnews2.Eng.Sun.COM> Distribution: world Nntp-Posting-Host: beelzebub