On 10.08.2017 21:11, Daniel wrote:
> On Wednesday, August 9, 2017 at 5:15:00 PM UTC-4, Mr Flibble wrote:
>> First page of documentation for my C++ GUI/game lib, neoGFX (coming soon):
>>
>>
http://neogfx.io/wiki/index.php/NeoGFX_C%2B%2B_Code_Naming_Convention
>>
>
> (1)
>
> for (auto const& g : iGrades)
> total += g;
>
> should be
>
> for (auto g : iGrades)
> total += static_cast<char>(g);
I bet Mr Flibble was the victim of editing here.
Marshall Cline once gave me the advice to do as he did with the FAQ's
examples for the FAQ book: compile them all, no matter how trivial.
So, good catch, as they say, but instead of the `static_cast` I'd rather
fix the `enum` definition, e.g. replace
enum class grade
with
struct Grade { enum Enum {
which fixes the one thing that was ungood about C++03 enumerations,
namely lack of qualification of value names, without dragging in the new
ungoodness of C++11 enumerations, namely lack of implicit conversion to
integer values.
Also I'd use `auto const` rather than just `auto`: that's a nice
possibility with range based `for`, and I think it deserves to be used
by default, only leaving off the `const` when that has a /purpose/.
> (2)
>
> << static_cast<char>(s.average_grade() + 'A')
>
> should be
>
> << (static_cast<char>(s.average_grade()) + 'A')
Eagle eyes! :)
Cheers!,
- Alf