diff --git a/src/libraries/JANA/Utils/JTypeInfo.h b/src/libraries/JANA/Utils/JTypeInfo.h index 6de0fc5b1..39762c401 100644 --- a/src/libraries/JANA/Utils/JTypeInfo.h +++ b/src/libraries/JANA/Utils/JTypeInfo.h @@ -12,6 +12,20 @@ namespace JTypeInfo { + +template +struct is_parseable : std::false_type {}; + +template +struct is_parseable() >> std::declval())>> : std::true_type {}; + +template +struct is_serializable : std::false_type {}; + +template +struct is_serializable() << std::declval())>> : std::true_type {}; + + template std::string demangle(void) { diff --git a/src/programs/tests/JParameterManagerTests.cc b/src/programs/tests/JParameterManagerTests.cc index 3a3d7b4fc..19209af77 100644 --- a/src/programs/tests/JParameterManagerTests.cc +++ b/src/programs/tests/JParameterManagerTests.cc @@ -402,4 +402,35 @@ TEST_CASE("JParameterManager_Issue217StringsWithWhitespace") { } } +#if __cplusplus >= 201703L +template +void fakeParse(std::string s, T& out) { + constexpr bool parseable = JTypeInfo::is_parseable::value; + static_assert(parseable, "Type is not automatically supported by the ParameterManager. To use, implement a template specialization for Parse(std::string in, T& out)."); + if constexpr (parseable) { + std::stringstream ss; + ss >> out; + } +} +#else +template +void fakeParse(std::string s, T& out) { + std::stringstream ss; + ss >> out; +} +#endif +} + + +enum class Mood {Good, Bad, Mediocre}; +TEST_CASE("Error message on bad parse") { + int x; + fakeParse("22", x); + Mood m; + fakeParse("Mediocre", m); +} + + + +