[Boost.Function] (too) loosly treated argument types
Given example below, is there any way to enforce parameter type strictness?
[-- Example begin:
#include
On Dec 27, 2006, at 5:00 PM, Slawomir Lisznianski wrote:
Given example below, is there any way to enforce parameter type strictness? [snip] typedef function1
signature; void fn1(int v) // notice arg by-value (say, user typo) { // here, assignments to `v' are lost after // return } [snip] // I want this to fail at compile-time... signature f1 = fn1; [snip] On my compiler (g++ (GCC) 4.0.2 20051125) everything compiles fine but ideally, I'd like to fail the first case.
I don't know of any way to enforce parameter type strictness. It would probably require looking into the actual function object that the user has passed, then using some kind of metaprogram to determine if the parameters are strict enough.
Rationale: Users of my library register callbacks and occasionally mistype their function signature which causes them to modify temporaries rather than "out" variables.
I don't know what to tell you. Function is designed to allow conversions in its parameter types; if you really need a strict signature, Function might be the wrong choice. Cheers, Doug
Doug Gregor wrote:
On Dec 27, 2006, at 5:00 PM, Slawomir Lisznianski wrote:
Given example below, is there any way to enforce parameter type strictness? [snip] typedef function1
signature; void fn1(int v) // notice arg by-value (say, user typo) { // here, assignments to `v' are lost after // return } [snip] // I want this to fail at compile-time... signature f1 = fn1; [snip] On my compiler (g++ (GCC) 4.0.2 20051125) everything compiles fine but ideally, I'd like to fail the first case.
I don't know of any way to enforce parameter type strictness. It would probably require looking into the actual function object that the user has passed, then using some kind of metaprogram to determine if the parameters are strict enough.
I think the signature can to some extend be respected by passing something line a boost::reference_wrapper<int> instead of an int&. -Thorsten
participants (3)
-
Doug Gregor
-
Slawomir Lisznianski
-
Thorsten Ottosen