fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

10K
active users

Gareth Lloyd (He/him)

I have run this exercise with multiple C++ developers from junior to senior. Its a simple task that can reveal strength/weakness in a devs understanding of what good C++ could look like.

Implement a reverse words function that works in-place on the string provided.
- Make it correct
- Make it performant
- Make it maintainable

Give it a go. I'll also post content warning hint(s) as replies.

godbolt.org/z/9faxG7K4b

godbolt.orgCompiler Explorer - C++ (x86-64 clang 17.0.1) void reverse_words(std::string &) noexcept { // Implement here } int main() { using namespace std::string_literals; auto str = "Can you reverse these words?"s; reverse_words(str); assert(str == "words? these reverse you Can"); }

@glloyd This is a rotate and I claim my five pounds!

@jezhiggins @glloyd
Funny, but with the space, that's just more complicated. Also, the rotate is O(n*m) performance, not O(n)