Convert<T>::to_pattern()) = delete;
};
+ /**
+ * A utility function that simplify the convertion to strings of arbitrarily
+ * complex types.
+ *
+ * This function calls the method Convert<T>::to_string() with the default
+ * pattern. An example usage is the following:
+ *
+ * @code
+ * auto t = std::make_tuple(1.0, std::make_pair(1, "ciao"));
+ * auto s = Patterns::Tools::to_string(t);
+ *
+ * std::cout << s; // will print "1 % 1 : ciao
+ * @endcode
+ *
+ * @author Luca Heltai, 2018
+ */
+ template<typename T>
+ std::string to_string(const T &t);
+ /**
+ * A utility function that simplify the convertion from strings to arbitrary
+ * types.
+ *
+ * This function calls the method Convert<T>::to_value() with the default
+ * pattern. An example usage is the following:
+ *
+ * @code
+ * auto t = std::make_tuple(1.0, std::make_pair(1, "ciao"));
+ * to_value("2 % 3 : mondo", t);
+ * auto s = Patterns::Tools::to_string(t);
+ * std::cout << s; // will print "2 % 3 : mondo
+ * @endcode
+ *
+ * @author Luca Heltai, 2018
+ */
+ template<typename T>
+ void to_value(const std::string &s, T &t);
/**
* @addtogroup Exceptions
}
};
+ // Utility function with default Pattern
+ template<typename T>
+ std::string to_string(const T &t)
+ {
+ return Convert<T>::to_string(t);
+ }
+
+ // Utility function with default Pattern
+ template<typename T>
+ void to_value(const std::string &s, T &t)
+ {
+ t = Convert<T>::to_value(s);
+ }
}
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Check to_string and to_value
+
+#include "../tests.h"
+#include <deal.II/base/parameter_handler.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <memory>
+
+using dealii::Patterns::Tools::to_string;
+using dealii::Patterns::Tools::to_value;
+
+int main()
+{
+ initlog();
+
+ auto a = std::make_tuple(1, std::string("ciao"));
+
+ auto s = to_string(a);
+ to_value("2 : mondo", a);
+
+ deallog << "From: " << s
+ << " to " << to_string(a) << std::endl;
+}