|
Boost : |
Subject: Re: [boost] Interest in a tweener library
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2012-07-16 07:50:43
Julien Jorge wrote:
> Le Sun, 15 Jul 2012 13:37:06 +0200,
> Klaim - Joël Lamotte <mjklaim_at_[hidden]> a écrit :
>
> > Did you consider copying the value instead of keeping a
> > reference to it? Also, what do you think about allowing the
> > user to use one or the other?
>
> Sorry I made a mistake in the code that results in a
> misunderstanding.
> The argument of the function g() should not be a reference:
>
> void g( boost::function<double (double)> func )
> {
> double t = /* ⦠*/;
> double d = func( t );
> // â¦
> }
>
> int main()
> {
> g( &f );
> }
>
> Thus, it is a copy of the function object. There is no reason
> to keep a reference to the boost::function here.
From what you've posted, there's no need to copy the boost::function object.
Anyway, if g() were a function template, then the compiler could inline the call to f():
double
f()
{
// ...
}
template <class F>
void
g(F _function)
{
double const t(/*...*/);
double const d(_function(t));
// ...
}
int
main()
{
g(f);
}
_function(t) would actually be f(t), with no boost::function object, and it could be inlined. That, however, requires that the caller create boost::function objects when those are needed to bind arguments, including this pointers.
If g() would be bloated because most of the code is not dependent on F, then factor out code before and after calling the function argument into non-template helper functions called by g().
_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com
________________________________
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk