Topic: void as an ordinary type
Author: sra@ecs.soton.ac.uk (Stephen Adams)
Date: 22 Apr 92 19:56:51 GMT Raw View
Has there ever brrn a proposal to make void a legal type for
ordinary variables and structure/class data members?
What I am thinking of is making the handling of void more
like other types (e.g. int).
. A variable /data member of type void takes 0 bytes of
storage
. constructs assigning to or using the value of a void
storage location do not generate stores or loads
This might at first seem like a silly idea, but I have on
several occasions wanted to use it.
The situation where I would find it useful is for writing
and using templates. A general template definition is
sometimes useful in a reduced role. For example, Set<T>
could be implemented using Map<T,void>. There would be no
wasted storage, and the Map specific methods, like
U& Map<T,U>::valueAt(T&)
could be hidden by some technique like private inheritance.
Has this idea come up before? If it has I could someone
tell me what happened, and if not, is there any interest in
the idea? I think that it could be made to work without
breaking existing parts of the language. The benefits would
be:
. Allowing reuse by eliding irrelevant data (like Set<T>)
. More uniformity in the language
. The type void& has merits similar to void*
--
Stephen Adams Email: S.R.Adams@ecs.soton.ac.uk
Electronics and Computer Science Tel: 0703 593649
University of Southampton Fax: 0703 593045
Southampton SO9 5NH, UK