lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make Pitch::to_string() more robust (issue 581580043 by address@hidd


From: nine . fierce . ballads
Subject: Re: Make Pitch::to_string() more robust (issue 581580043 by address@hidden)
Date: Sat, 01 Feb 2020 03:19:12 -0800

https://codereview.appspot.com/581580043/diff/557260048/lily/pitch.cc
File lily/pitch.cc (right):

https://codereview.appspot.com/581580043/diff/557260048/lily/pitch.cc#newcode162
lily/pitch.cc:162: if (qt >= 0 && qt < int (sizeof(accname) /
sizeof(const char*))) {
Instead of casting to int and checking that the value is non-negative,
why not 

  size_t qt = ...
  if (qt < ...)

A pre-C++11 way to improve computing the array size is not to repeat the
element type:

  sizeof (accname) / sizeof (accname[0])

A C++11 way to simplify the code that uses the size is to use
std::array, though it would come at the cost of declaring the count.

  #include <array>
  ...
  static const std::array<char const *, 9> = {"eses" ...
  ...
  size_t qt = ...
  if (qt < accname.size ())

https://codereview.appspot.com/581580043/diff/557260048/lily/pitch.cc#newcode162
lily/pitch.cc:162: if (qt >= 0 && qt < int (sizeof(accname) /
sizeof(const char*))) {
Space after sizeof?

https://codereview.appspot.com/581580043/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]