I have a number of different class types each with the member function GetParameterString() which returns a string specific to the class. I'd like to be able to store these class types in a boost::mpl::list and compare GetParameterString to a test string that I receive from another source. So if I have 3 class types, I'd like to do something like the following:
const std::string input_string = "Random String";
using ClassTypes = boost::mpl::list<ClassA, ClassB, ClassC>;
auto it = boost::mpl::find_if<ClassTypes>( [&input_string](auto next_class){
return input_string.compare(next_class.GetParameterString() )
});
it->CallSomeOtherCommonClassMethod();
There are two problems here. First the return value is an int and not a bool. But more importantly, how I've set up the call to boost::mpl::find_if seems incorrect even if I return a bool.
One of my requirements here is to stick to boost::mpl. Thanks in advance!
boost::mpllibrary is mostly compile-time-only, and it operates purely on types rather than values (boost::mpl::for_eachis an exception). The result of itsfind_ifis one of the classes, not a value of any type. "lambda" passed in it is not the usual C++ lambda either.You may be able to achieve what you want if
getParameterString()isstatic constexprmember function. You would need to figure out how to create the right typePredicate. Once you have that, your code should look like: