String Trimmer and trimmed Input routine
typename std::basic_string&lt;Ch, Tr, Alloc&gt;::const_iterator e = str.end();
...

// Query: this loop looks u-g-l-y. Can it be less ugly?
  while( b != e ) {
    e--;
    if(!std::isspace(*e, loc)) {
      e++;
      break;
    }
  }


This looks weird and tends to go UB.

1) e = str.end();

2) e--; /* it's better to use --e in this case */ you move one more far position after end()!!!

3) std::isspace(*e, loc) &lt;--- UB, accessing the memory that haven't been allocated

If you need to find the first and the last spaces in the string, use this:

b = find_if(str.begin(),  str.end(),  isspace_predicate);
e = find_if(str.rbegin(), str.rend(), isspace_predicate);