Diogo Benvenutti (2) [Avatar] Offline
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 (97) [Avatar] Offline
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