Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-29 23:10:45


----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, January 29, 2002 10:35 PM
Subject: [boost] Boost.Function optimization for stateless function objects

> I've just committed some changes to Boost.Function so that it will
optimize
> away unnecessary allocations and copying of stateless function objects.
Thus,
> construction of or assignment to a Boost.Function object given a stateless
> function object will not throw, and will not allocate any memory.
>
> To do this, a new type trait, is_stateless, has been added to
> boost/type_traits/object_traits.hpp. The definition of is_stateless is:
>
> template <typename T>
> struct is_stateless
> {
> BOOST_STATIC_CONSTANT(bool, value =
> (::boost::type_traits::ice_and<
> ::boost::has_trivial_constructor<T>::value,
> ::boost::has_trivial_copy<T>::value,
> ::boost::has_trivial_destructor<T>::value,
> ::boost::is_class<T>::value,
> ::boost::is_empty<T>::value
> >::value));
> };
>
> The functionality has been tested under GCC, Comeau, and MSVC without any
> problems. Documentation may lag behind a bit, but I'm working on it.
>
> Comments always welcome.

Cool!

So, as I understand it, is_stateless requires user intervention or compiler
support, right?
It seems to me that you'd want is_stateless to be true in the following
cases:

    T is a function pointer
    T is const (? maybe not -- there might be a state* const in it)

-Dave


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