lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [PATCH] C++ m11n: range-based for loops


From: Greg Chicares
Subject: Re: [lmi] [PATCH] C++ m11n: range-based for loops
Date: Sun, 15 Jan 2017 03:32:38 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 2017-01-11 22:39, Vadim Zeitlin wrote:
> 
>               https://github.com/vadz/lmi/pull/52

Do you see any reason why I should not apply the following patch in
addition? The array should be const, of course. And the for loop is
almost identical to the one in DurationModeChoice's ctor a few lines
above. SetStringSelection() is probably slower than SetSelection(),
but I doubt that makes a noticeable difference. Alternatively, we
could add a counter in the loop and call SetSelection(counter), but
I'm not sure that's worth the extra code.

---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
--- a00/52b/input_sequence_entry.cpp    2017-01-14 23:36:42.329382936 +0000
+++ ./input_sequence_entry.cpp  2017-01-14 23:47:08.030305282 +0000
@@ -75,7 +75,7 @@
     char const*   label;
 };
 
-choice_value duration_mode_choice_values[] =
+static choice_value const duration_mode_choice_values[] =
   {
     {e_retirement,       "until retirement"},
     {e_attained_age,     "until age"},
@@ -137,11 +137,11 @@
 
 void DurationModeChoice::value(duration_mode x)
 {
-    for(unsigned int i = 0; i < duration_mode_choices; ++i)
+    for(auto const& i : duration_mode_choice_values)
         {
-        if(x == duration_mode_choice_values[i].mode)
+        if(x == i.mode)
             {
-            SetSelection(i);
+            SetStringSelection(i.label);
             return;
             }
         }

--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------




reply via email to

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