[Dune] ParameterTree

Carsten Gräser graeser at math.fu-berlin.de
Fri Jan 28 00:50:28 CET 2011


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.
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);

If no one objects I'll commit this next week.

Best,
Carsten




More information about the Dune mailing list