Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2007-01-02 11:37:17


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<void, int &> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net