The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Diogo Benvenutti (2) [Avatar] Offline
#1
Hello there,

here is just a small suggestion that I would like to point out. On Listing 9.9. "Swap function for expected<T, E>", there is a alias to std::swap (using std::swap). But then on line 14 there is a call to std::swap (using std:: ), and then on line 21 there's a call without the std namespace prefix. Wouldn't it be better not to use the alias, so it clearly states the calls to std::swap? Also, since the name of the function is also swap, it can get a bit confusing.

Awesome book by the way! = )
Ivan Cukic (104) [Avatar] Offline
#2
Sorry for the late response.

The using std::swap here means that swap will call either a specialized swap for the types T and E if there is one, or fall back to std::swap. For bools, (m_valid) it wants to explicitly call the std::swap to avoid any ambiguity. It would also work without the std::, but I like to specify things more explicitly - so that whoever reads the code sees what is the generic part of the function and what is not.

> Awesome book by the way! = )

Thanks, glad you like it! smilie