Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 1999-12-01 06:51:22


Beman wrote:
> One problem we ran into was that we wanted something which was not
> subject to inadvertent misuse. For example, we had several
> implementations of a "require" template class, which you could
> inherit or instantiate:
>
> template<typename T>
> class foo : require< std::numeric_limits<T>::is_integer > {...};
>
> The problem was that it could be misused:
>
> template<typename T>
> class foo
> {
> require< std::numeric_limits<T>::is_integer >;
> };
>
> This code looks right, but is actually totally ineffective (because
> it should have been coded "require<
> std::numeric_limits<T>::is_integer > some_name;").
>
> Any compile time assert should be bullet-proof, IMO.

I'm not convinced:
1. compile-time assertions will be primarily for the advanced user and
library programmer. The library's clients will get the benefit of the assert
at compile time, when used properly

2. The problem you describe is no worse than many other pitfalls in the
language; you have to know the language rules.

e.g.

class mutex;
void foo()
{
    mutex(); // Oops; does nothing!

    ...
}

3. You could improve things by changing the name to require_t, making the
error you describe less likely.

-D


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