[Dune] ParameterTree
Jö Fahlke
jorrit at jorrit.de
Fri Jan 28 01:27:42 CET 2011
Am Fri, 28. Jan 2011, 00:50:28 +0100 schrieb Carsten Gräser:
> Dear Dune,
> for for historical reasons ParameterTree contains
>
> int ParameterTree::get(const string& key, int default);
> double ParameterTree::get(const string& key, double default);
>
> and the new methods with template parameter
>
> template<class T>
> T ParameterTree::get(const string& key, const T& default);
>
> IMHO we should removed the non-template methods since for
> key=0.1 you have the really ugly behaviour
>
> get("key", 1.0) == 0.1
> get("key", 1) == 0
>
> due to the internal usage of atoi(). With the newer template methods
> you get an exception in this case since they use streams for conversion.
Seconded. We should probably drop the overload for std::string as well (but
we should keep the one for char*).
> However the essential problem persists since the implicitly derived
> conversion type might not be what you expected. For example for key=1
> you have
>
> char defaultValue=0;
> get<int>("key", defaultValue) == 1
> get ("key", defaultValue) == 49
>
> In order to avoid this I suggest to forbid implicit determination
> of the template argument using
>
> template<class T>
> struct DefaultType
> { typedef T type };
>
> template<class T>
> T ParameterTree::get(const string& key, const DefaultType<T>::type& default);
Objection.
I always understood the implicit determination of the conversion type as the
official way to select the particular overload of the get()-method with
default parameter, and I'm using it extensively. The simple fact that these
methods were sometimes implemented as overloads made this the only reliable
way. I consider The fact that most of these overloads are provided by a
method template an implementation detail.
Instead I propose specialize the ParameterTree::Parser struct for char to read
a numerical value instead of a character.
Bye,
Jö.
--
In the beginning the Universe was created. This has made a lot of
people very angry and been widely regarded as a bad move.
-- Douglas Adams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20110128/e1ca546c/attachment.sig>
More information about the Dune
mailing list