From a3963b0780dd69bc8bbee98e17c22cc92f4f14ec Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Mon, 1 Aug 2016 11:15:13 +0200 Subject: [PATCH] [App/IO] compile-time type check --- Applications/FileIO/CsvInterface.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Applications/FileIO/CsvInterface.h b/Applications/FileIO/CsvInterface.h index a6653f888d3..fc014f3f399 100644 --- a/Applications/FileIO/CsvInterface.h +++ b/Applications/FileIO/CsvInterface.h @@ -54,16 +54,14 @@ public: template<typename T> bool addVectorForWriting(std::string const& vec_name, std::vector<T> const& vec) { - if (typeid(vec) == typeid(std::vector<std::string>) || - typeid(vec) == typeid(std::vector<double>) || - typeid(vec) == typeid(std::vector<int>)) - { - _vec_names.push_back(vec_name); - _data.push_back(vec); - return true; - } - ERR ("Vector type currently not supported."); - return false; + static_assert(std::is_same<T, std::string>::value + || std::is_same<T, double>::value + || std::is_same<T, int>::value, + "CsvInterface can only write vectors of strings, doubles or ints."); + + _vec_names.push_back(vec_name); + _data.push_back(vec); + return true; } /// Writes the CSV file. -- GitLab