|
From: | John W. Eaton |
Subject: | Re: value extractors for octave_value class |
Date: | Thu, 12 Nov 2015 11:46:18 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 |
On 11/11/2015 11:21 PM, Jordi Gutiérrez Hermoso wrote:
On Wed, 2015-11-11 at 11:59 -0500, John W. Eaton wrote:When overloading these functions with (for example) Array<double> vector_value (const char *fmt, ...) const; some compilers complained that the overloaded function was ambiguous. I'm not sure what is best here.How about just overloading with std::string arguments and requiring the function caller to use sprintf in case they need formatting? So, for example, auto x = foo.int_value(sprintf("error: want %s but got %s", bar, baz))
I don't think we should be using "auto" in Octave code just yet.Some reasons to not do this are that sprintf requires a buffer to be allocated, so that would complicate things and the sprintf operation and the std::string object creation would happen on each call even if they are never needed. With the fmt+varargs approach, the arguments just need to be passed (as pointers) and if the error doesn't happen, then the formatting doesn't have to be done.
jwe
[Prev in Thread] | Current Thread | [Next in Thread] |