|
Boost : |
From: Hamish Mackenzie (boost_at_[hidden])
Date: 2001-11-27 19:49:26
On Wed, 2001-11-28 at 00:21, David Abrahams wrote:
> Firstly, runtime and compile-time behavior are different domains, and so may
> well live in different namespaces.
>
> Secondly, Aleksey and Emily were just discussing a hybrid:
>
> template<typename T>
> struct identity : public unary_function<T, T> {
> const T& operator()(const T& x) const throw()
> {
> return x;
> }
> typedef T type;
> };
Cool.
On a similar note does boost have a lightweight runtime typeid system?
Here is what I use. It can only tell you if two types are exactly
matched (no is_a information) but the overhead should be just 4 to 8
bytes per type depending on alignment. And perhaps more importantly it
works on any type.
From memory, as I don't have it in front of me right now...
class lightweight_type_id
{
public:
lightweight_type_id() : ptr_( 0 ) {}
template< class Type >
static lightweight_type_id get() { return &id< Type >::dumby_; }
bool operator ==( const lightweight_type_id & id ) const
{
ptr_ == id.ptr_;
}
private:
template< class Type >
class id
{
public:
static const char dumby_ = 0;
}
lightweight_type_id( const char *p ) : ptr_( p ) {}
const char *ptr_;
};
Is there a way to reduce the static storage overhead?
Hamish
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk