Believe it or not, that doesn't compile because begin and end have different types due to begin/end returning different iterator types than rbegin/rend. It could be a bug in both clang and g++.
This works, but I don't like the &strt and &endp:
std::wstring trim(std::wstring theStr) {
auto strt = std::find_if_not(theStr.begin(), theStr.end(), std::iswspace);
if (strt == theStr.end()) return L"";
auto endp = std::find_if_not(theStr.rbegin(), theStr.rend(), std::iswspace);
return std::wstring(&*strt,&*endp+1);
}
The easiest way is to use Boost's string algorithms library, though: std::wstring trimb(std::wstring theStr) {
boost::trim(theStr);
return theStr;
}