I am using c++. I have string which can contains element start with ^
and end with $
. This element can be int
or string
.
Example:
"....^15$asdasd"-> 15
"...^bbbb$ccc"->"bbbb"
I would like to write lambda function which would do this. If I use template function the code would look like this:
template <typename T>
T getElem(string S)
{
T retElem;
// make calculations
// ....
return retElem;
}
but when I try using generic lambda I am reaching this situation :
auto getElem = [] () {
T retElem;
// make calculations
// ....
return retElem;
};
the problem is how to get type of retElem. Is there a way to use lambda in this case. I want to use generic lambda in function, where such such extraction is used. I want to to encapsulate this logic only in the function.