It's generic lazy computation that doesn't modify the original structure nor allocate a new one. It's O(1). It's extremely simple. It's a few characters of code. The name is explicit and there is no doubt to what it does.
That's one of the best solutions. The second best solution is an eager solution that modifies it in-place, but it's better to do it generically for any bidirectional range. I can't think of any case where the eager solution would be a better choice however.
That's not over-engineering. That's using the right generic tool to do the job, so that the tool only needs to be implemented once and can be reused anywhere providing you use the right abstraction.
I personally wouldn't want to work on a job that has so lame interviews anyway. It's such a trivial problem, and they expect a really specific non-elegant solution that a sane person wouldn't ever use in real life.
If they're against boost, you can rewrite it yourself. It's fairly easy. But if they have the NIH syndrome, that's another reason not to work there anyway.
Quote:NB: His code is const correct - the intention is to modify the string.
As a matter of fact, he doesn't.
His source string is a string literal anyway, and it is not allowed to modify it. In C++ string literals are const char[N] to prevent that kind of mistakes.
His code is extremely bad anyway, even for C.
Quote:I don’t know if there are compilers with 100% C99 support. It isn’t a very successful standard.
GCC has decent support for it. But only EDG has full C99 support IIRC.