Boost logo

Boost :

From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2004-12-01 10:42:50


On Tue, 30 Nov 2004 23:28:48 -0600
"Aaron W. LaFramboise" <aaronrabiddog51_at_[hidden]> wrote:

> This is very useful information!

I hope it is correct ;-) Can you verify similar performance
characteristics?

> The primary observation I make from this is how much slower by ratio
> Boost.Signals is. I'm going to look at your test 'lite'
> implementation later. Is there some additional feature Boost.Signals
> is offering that causes it to do all of this extra work?

Strictly guessing here... probably something to do with combining the
return values

On a different note,I have resisted looking at Boost.Preprocessor for a
long time (since the first look made my head spin). However, after just
reading a post on boostpp, relative to expanding parameters, I decided
to wade into the shallows. Here is the result, in case you want to play
with larger arity, or want to change the operator() code...

I have to admit that a devilish grin started forming on my face as I was
writing this little piece of code, which should be a good replacement in
the Signals.hpp file. Replace the rest of the file starting with

template <typename Signature>
struct Signal;

------------------------------------
template <typename Signature>
struct Signal;

} // end signals namespace

} // end lite namespace

// Generate the code for all Signal<> specializations.
#include "boost/preprocessor/repetition.hpp"
#include "boost/preprocessor/arithmetic/add.hpp"
#include "boost/preprocessor/punctuation/comma_if.hpp"
#include "boost/preprocessor/comparison/less.hpp"
#include "boost/preprocessor/facilities/empty.hpp"

#ifndef LITE_SIGNAL_MAX_ARITY
#define LITE_SIGNAL_MAX_ARITY 10
#endif

#undef LITE_PP_DEF
#define LITE_PP_DEF(z, n, lastn) \
  template <typename R \
      BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename T)> \
  struct Signal < R ( BOOST_PP_ENUM_PARAMS(n,T) ) > \
    : public detail::Signal_Base<R (BOOST_PP_ENUM_PARAMS(n,T))> \
  { \
    R operator()( BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) const \
    { \
      typename list::iterator i = list_.begin(); \
      while (i != list_.end()) \
      { \
        if (i->function_) \
        { \
          (i++)->function_( BOOST_PP_ENUM_PARAMS(n,t) ); \
        } \
        else \
        { \
          i = list_.erase(i); \
        } \
      } \
    } \
  } BOOST_PP_IF(BOOST_PP_LESS(n, lastn), ;, BOOST_PP_EMPTY())

namespace lite
{

namespace signals
{

BOOST_PP_REPEAT( \
    BOOST_PP_ADD(LITE_SIGNAL_MAX_ARITY, 1), \
    LITE_PP_DEF, \
    LITE_SIGNAL_MAX_ARITY);

} // end signals namespace

} // end lite namespace

#undef LITE_PP_DEF

#endif // lite__Signal__hpp_


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