Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2002-10-28 00:54:33


Aleksey Gurtovoy <agurtovoy_at_[hidden]> writes:

| Gabriel Dos Reis wrote:
| > The way I'm intending to implement compiler support for type traits in
| > GCC is to have "built-in" operators like __builtin_xxx() (xxx ranging
| > over is_pod, has_trivial_copy_ctor, has_trivial_dtor, ...) to take a
| > type-id and return boolean constant expression.
| >
| > Therefore,
| >
| > | template< typename T > struct is_pod
| > | {
| > | BOOST_STATIC_CONSTANT(bool, value =
| >
| > will be written
| >
| > BOOST_STATIC_CONSTANT(bool, value = __builtin_is_pod(T))
| >
|
| Interesting! But wouldn't it be easier just to drop
|
| template<typename X> __yes_type __builtin_is_pod();
|
| into the global scope when X is defined/instantiated for the first time (if
| it's a template class)?

Actually, it is easier the other way (i.e. as an operator) -- it just
took me about few minutes before embarking on valarray issues on
Wednesday morning :-)

If implemented as a function template, I would have to keep track of
every template instantiation. That wastes time and memory for no gain.

And, since this is intended to be a compiler magic, I really want it
to be an operator, a not a function template that would give the
impression of being specializable -- it can't be.

| After all, there isn't much of a difference between
|
| BOOST_STATIC_CONSTANT(bool, value = __builtin_is_pod(T))
|
| and
| BOOST_STATIC_CONSTANT(bool, value = sizeof(__builtin_is_pod<T>())

much difference in terms of what? The second is waste of time and
memory; it will be implemented in terms of the former.

| > 1)
|
| Just wondering if these built-in operators worth the complications of
| introducing them :).

They are easier to handle correctly than the function template
conterpart. And, to support them the compiler would have to implement
the operator machinery AND waste memory and time.

| > [ FWIW, I implemented the static-assert support in GCC at Santa Cruz,
| > just after reporting (Robert, Judy and me) on the proposal.
| > It isn't yet in FSF official source ]
|
| Cool! I hope other vendors will follow the trend with equal eagerness :).

Well, I implemented the proposed feature (with the expression syntax)
because Robert and I have been discussing some points and also I
really wanted to know how useful it really is (compared to other
approaches). I hope to have it in the FSF official source as soon as
possible. I will drop a note here for testing as soon as it is in
(unless you're impatient and want to test it now, in which case I can
send you a patch against GCC experimental source).

-- Gaby


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk