Boost logo

Boost :

Subject: Re: [boost] Design conventions; passing functors
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-11-06 11:43:17


AMDG

Joachim Faulhaber wrote:
> <snip>
>
> template<class Domain, class Codomain, ...>
> class interval_map{
> //(3) Adaptable functor
> template<template<class>class Combinator>
> interval_map& add(const value_type& value_pair,
> const Combinator<Codomain>& combine)
> { /*combine functor passed or called somewhere*/ }
>

Can't you use:

template<class Combinator>
interval_map& add(const value_type& value_pair, const Combinator& combine);
?

In other words, does Combinator really have to be a template?

> Now, there seems to be a convention from the STL that functors
> shall be passed BY VALUE.
>
> <snip>
>
> I do not really understand this convention and feel some
> resistance to follow it. In addition the call by value
> implementation can (and will) lead to heavy inefficiency
> by unaware usage of fat functors.

The assumption is that function objects are not fat.
If you have a large function object, it is always
possible to create another function object that just
stores a reference to the original function object.

> So I browsed through
> some boost libraries and found that functors are passed by
> reference there (e.g. accumulators, fusion).
>
> Final question: What is the boost standard on passing functors,
> that I can adapt to?
>

You can go either way. There is no official Boost policy about this.

In Christ,
Steven Watanabe


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