So C++17 is on the horizon and will add many useful features . A couple that I think would be beneficial to this section are
- Structured bindings
if/switch (init, condition)
std::string_view
- And possibly
std::variant | std::optional | std::any
An example of structured bindings and if initialiser.
std::set<char, bool> LetterSeen; // setup our map
for (auto Letter : Word) // for all letters of the word
{
Letter = tolower(Letter); // handle mixed case
if (const auto [Iter, Inserted] = LetterSeen.insert(Letter); !Inserted)
{
return false; // we do NOT have an isogram
}
return true;
}
So the const auto [Iter, Inserted] = LetterSeen.insert(Letter)
would create two variables Iter
and Inserted
which are the unpacked return value (std::pair<iterator, bool>
) of the insert. Then using the bool for the if statement. (Of course you could just do if (!LettersSeen.insert(Letter).second)
but this is the first example that came to mind for structured bindings and if(init, condition)
). I feel like these two along with constexpr if
would probably make their uses in UE4.
And then std::string_view
would essentially replace const std::string&
as parameter types (which you don’t actually do in this section but still seems worth a mention)
P.S. To anyone who was using the deprecated std::random_shuffle
for getting random words from an array, that has now been removed in C++17 and you’ll have to use std::shuffle
along with an engine.