|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-07 11:18:27
Terje Slettebø <tslettebo_at_[hidden]> writes:
> The types yes_type and no_type (or equivalent) - that is, two types which
> are guaranteed to have different size - is used extensively for Boost type
> traits, and also in some other libraries (iterator.hpp,
> named_template_params.hpp, multi_array, Phyton and signals). Some places use
> the type traits ones (<boost/type_traits/detail/yes_no_types.hpp>), other
> define them themselves.
>
> In the type traits docs (or any other docs I've found), these aren't
> mentioned (and they are defined in the "detail"-directory, suggesting it's
> an implementation detail). Yet, other libraries use them, as well. Perhaps
> these should be documented, so they may be relied on, and other libraries
> may avoid having to define them, themselves?
Sure! Submit a patch (with docs) for the utility library.
> By the way, these are defined as char and double, respectively. Are these
> required to have different size?
No. I thought we changed them to char(&)[1] and char(&)[2].
> I haven't found that guarantee in the C++ or C
> standard. Theoretically, you might have an architecture which
> operated only on values of one size, so that char and double would
> have the same size.
>
> In that case, maybe something like this could be safer:
>
> typedef char yes_type[1];
> typedef char no_type[2];
They have to be references or you can't return them ;-)
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk