Boost logo

Boost :

From: Andrey Tcherepanov (moyt63c02_at_[hidden])
Date: 2008-07-23 14:54:23

On Tue, 22 Jul 2008 11:22:06 -0600, Mathias Gaunard
<mathias.gaunard_at_[hidden]> wrote:

> Andrey Tcherepanov wrote:
>> Oh, no... I think the fact that Boost.Function allows storing of null
>> pointer ("there is no function to call") is a good thing!
> Well, if you like the possibility of invoking undefined behaviour, it is
> surely a good thing.
> I would rather have the type system and the exception mechanism make
> sure that can never happen.

bad_function_call will be thrown right now


>> To disallow default
>> constructor (no argument passes) completely will be way too limiting
> I don't really see how.
> If you want a function that might or might not be there, you can use
> optional<function<sig> >.

Hmm... and what will happen if I call this when it is not initialized yet?

>> it is a encapsulation of function with pointer to function sort-of
>> behaviour, not reference to it.
> Yes, the reason Boost.Function behaves that way is to be consistent with
> function pointers.
> But maybe it could actually try to be better than these and provide
> safer guarantees.

So (if I understand you correctly), you want not function-pointer
but something more like reference - have to be initialized, cannot be null?
It is usable, indeed, but instead of modifying existing Function
(and fix all the user code), may be it is easier to create something new,
something like FunctionRef library?... Another way would be (sorry, I am
of brainfa...storming here :) ) add a "policy" template parameter for
storage, and
default it so existing code will not be broken.

BTW, shall it be not reassignable too? If not, assignment should work like
atomic op, and I am not sure if this is possible to implement for all user
arguments simultaneously.

[some stuff skipped, but I have no comment on it]

> Putting dummy functions is of course out of the question.

Hmm... working like a charm for me when I grow tired of checking emptiness
of the func pointers....

Best regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at