I seem to have hit a bit of a snag again.
I wanted to make it possible to couple (I think that's the right word?) my input class a little more, as to make it the answer itself, as well as the inputter of that answer.
To do that, I wanted to add verification as part of the process, as well as the possibility of a custom conversion std::string -> T.
Basically that would mean taking a functor in the constructor and storing it for later when the ask member function is called. But how would we do this? I cannot store it inside the class if I do not know the type... and to know the type, I would have to include it for the class template, which means explicitly specifying it which defeats the entire purpose...
The red part highlights the unknown. Taking a class functor is not really what I want. I basically want to make it work with lambda expressions that is coming with C++0x. A sample use of how to use the class would be:Code:template<typename Type, typename CharT = StrType_t, template<typename> class ValidateFunctor = ValidateDefault, template<typename> class Traits = InputTraits > class CInput
An example of how I would like an implementation is:Code:Stuff::Cinput<int> KeyLength( "Enter length of the key", [&] { cout << "Error. Invalid key."; }, [&] (int Key) -> bool { return (Key >= 2 && Key <= 5); });
I simply lack the know-how.Code:void ask(Type& Answer) { Answer = m_Converter(); if (! m_Validater(Answer) ) m_Error(); }



LinkBack URL
About LinkBacks




CornedBee