Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2001-08-30 05:41:12

> From: "Vesa Karvonen" <vesa.karvonen_at_[hidden]>
>> Yes, though replace "void" with a real (but useless) type, like:
>> struct unused {};
>hmn... Do you mean that 'void' is an illegal parameter for 'variant'?

FWIW, I personally consider "void" to be a real and useless type :->

>> Pointer syntax doesn't really make sense for variant or any, because there
>> no fixed return type for either. For optional and smart pointer, there is
>> only one possible type. This I think justifies the syntactic differences.
>I was mainly thinking of the following syntax:
> !x ...meaning... x.empty()
> if (x) ...meaning... if (!x.empty())
>And possibly:
> 0 == x ...meaning... x.empty()
> x == 0 ...meaning... x.empty()
>However, the usefulness of the above syntax is not very clear. It seems to me
>that 'vswitch' and 'cast' are the proper ways to use 'variant' and probably
>'any', too.

From experience I would recommend against it. The semantics of any, in
common with many other value types, is not sufficiently pointer-like to
justify the slight increase in convenience but noticeable relaxation in
type safety. The original any (or at least the one submitted to Boost)
had a UDC, but the review process convinced me to remove it.

And, for an extra EUR 0.02, supporting "x == 0" is an order of magnitude
less desirable than supporting "!x". Except for proper smart pointer
types, it is not worth pursuing the gymnastics involved in trying to
make this work and be reasonably type safe.


  Kevlin Henney phone: +44 117 942 2990
  mailto:kevlin_at_[hidden] mobile: +44 7801 073 508 fax: +44 870 052 2289
  Curbralan: Consultancy + Training + Development + Review

Boost list run by bdawes at, gregod at, cpdaniel at, john at