[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: recent change for "string enum varibles"
From: |
Jaroslav Hajek |
Subject: |
Re: recent change for "string enum varibles" |
Date: |
Tue, 18 May 2010 08:10:34 +0200 |
On Tue, May 18, 2010 at 8:04 AM, John W. Eaton <address@hidden> wrote:
> In the recent change for "string enum variables", you introduced a
> function
>
> octave_value
> set_internal_variable (int& var, const octave_value_list& args,
> int nargout, const char *nm, const char **choices,
> int nchoices)
>
> Which relies on NCHOICES properly counting the number of elements of
> CHOICES. I've generally tried to avoid things like this in Octave
> since it is easy for the number of elements of a variable wrong. If
> there is some good reason to avoid using a string_vector, std::list
> (or some other standard container),
The problem is that you can't (in C++98) supply static initializers
for containers, so you either need to recreate them each time
the function is called (unnecessarily slow), or use an extra static
function to init them (clumsy).
> then how about using 0 to mark
> the last element of CHOICES so you don't have to count the number
> of elements but instead look for 0 as the end of the array?
>
That's a good idea. This is safer and the extra work on user side is minimal.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz