結局こんな風にした。CGiveValueMethodFunctorはFunctorでなくて関数ポインターにしたかったけど、なぜかコンストラクターが関数ポインターを受け取らないのでFunctorにした
template <class CValue,class CGiveValueMethodFunctor>
class CValueWithGivenFlag
{
public:
bool given;
CValue value_;
CGiveValueMethodFunctor giveMethod_;
CValueWithGivenFlag(CGiveValueMethodFunctor &giveMethod):giveMethod_(giveMethod), given(false){}
CValueWithGivenFlag(CValue &valueInput, CGiveValueMethodFunctor &giveMethod): giveMethod_(giveMethod), given(true), value_(valueInput){}
CValue & value(){
if(given){
return value_;
}else{
giveMethod_(value_, given);
return value_;
}
}
void putValue(CValue &v)
{
given=true;
value_=v;
}
};