Boost logo

Boost Users :

From: Slawomir Lisznianski (slisznia_at_[hidden])
Date: 2006-12-27 17:00:35


Given example below, is there any way to enforce parameter type strictness?

[-- Example begin:

#include <boost/function.hpp>

using namespace boost;

// some kind of callback sig.
//
typedef function1<void, int &> signature;

void fn1(int v) // notice arg by-value (say, user typo)
{
   // here, assignments to `v' are lost after
   // return
}

void fn2(int & v) // OK
{
   // here, assignments to `v' are
   // preserved after return
}

int main(int, char**)
{
   // I want this to fail at compile-time...
   signature f1 = fn1;

   // ...and this to work
   signature f2 = fn2;

   return 0;
}

-- code end]

On my compiler (g++ (GCC) 4.0.2 20051125) everything compiles fine but
ideally, I'd like to fail the first case.

Rationale: Users of my library register callbacks and occasionally
mistype their function signature which causes them to modify temporaries
rather than "out" variables.

Thanks,

-- 
Slawomir Lisznianski
Paramay Group, LLC
"Programs for Research Machinery"

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