Re: void and this

From: David B. Held (dheld_at_codelogicconsulting.com)
Date: 10/07/03


Date: Tue, 7 Oct 2003 12:37:20 -0500


"Rolf Magnus" <ramagnus@t-online.de> wrote in message
news:blu1cq$jje$07$2@news.t-online.com...
> [...]
> The question is where could you practically use it? I mean,
> you can't use the parameters within your function, because
> they might not exist. So what are they useful for then?

You use type traits to see if an argument is void or not.
That's what is_void<> is for. To be truly useful, these functions
would have to be considered equivalent for overload purposes:

int foo(int);
int foo(int, void);

Then, you could do c'tor forwarding very nicely:

template <typename T, typename A1, typename A2 = void, ...>
auto_ptr<T> make_auto_ptr(A1 a1, A2 a2, ...)
{
    return new T(a1, a2, ...);
}

The call to new T() would only call c'tors that matched the right
number of non-void arguments. Of course, 'void' in the middle
of a non-void list would be ill-formed. Compare that to the
current way we have to do this with N overloads.

There are all kinds of places where forwarding occurs, or
doesn't occur, because it's too tedious to write the overloads.

> [...]
> void x;
>
> to state that x is not a variable.

But you do here:

int foo(void);

You just aren't allowed to name the "not-present variable".
And you can certainly cast to void:

(void) x;

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


Relevant Pages