diff --git a/api/api.hh b/api/api.hh index 4eb05e1c91..30d31a63d0 100644 --- a/api/api.hh +++ b/api/api.hh @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -231,7 +232,22 @@ public: return; } try { - value = T{boost::lexical_cast(param)}; + // boost::lexical_cast does not use boolalpha. Converting a + // true/false throws exceptions. We don't want that. + if constexpr (std::is_same_v) { + // Cannot use boolalpha because we (probably) want to + // accept 1 and 0 as well as true and false. And True. And fAlse. + std::transform(param.begin(), param.end(), param.begin(), ::tolower); + if (param == "true" || param == "1") { + value = T(true); + } else if (param == "false" || param == "0") { + value = T(false); + } else { + throw boost::bad_lexical_cast{}; + } + } else { + value = T{boost::lexical_cast(param)}; + } } catch (boost::bad_lexical_cast&) { throw bad_param_exception(format("{} ({}): type error - should be {}", name, param, boost::units::detail::demangle(typeid(Base).name()))); }