Commit f31c9945 authored by Dominik Charousset's avatar Dominik Charousset

Fix parsing of size_t config options

parent 3aad1fdf
......@@ -98,13 +98,15 @@ public:
}
private:
// Catches non-integer types.
template <class T>
static constexpr int idx(std::false_type /* is_integer */) {
static constexpr int idx(std::false_type) {
return detail::tl_index_of<legal_types, T>::value;
}
// Catches integer types.
template <class T>
static constexpr int idx(std::true_type /* is_integer */) {
static constexpr int idx(std::true_type) {
using squashed = detail::squashed_int_t<T>;
return detail::tl_index_of<legal_types, squashed>::value;
}
......@@ -117,8 +119,10 @@ protected:
return true;
}
// Catches any integer type that is smaller than int64_t.
template <class T>
static bool assign_config_value(T& x, int64_t& y) {
static typename std::enable_if<sizeof(T) < sizeof(int64_t), bool>::type
assign_config_value(T& x, int64_t& y) {
if (y < static_cast<int64_t>(std::numeric_limits<T>::lowest())
|| y > static_cast<int64_t>(std::numeric_limits<T>::max()))
return false;
......@@ -126,7 +130,11 @@ protected:
return true;
}
static bool assign_config_value(uint64_t& x, int64_t& y) {
// Catches size_t and uint64_t (yes, they differ on some compilers).
template <class T>
static typename std::enable_if<std::is_unsigned<T>::value
&& sizeof(T) == sizeof(int64_t), bool>::type
assign_config_value(T& x, int64_t& y) {
if (y < 0)
return false;
x = static_cast<uint64_t>(y);
......@@ -151,7 +159,8 @@ private:
char short_name_;
};
template <class T, bool IsInsertable = detail::can_insert_elements<T>()
template <class T,
bool IsInsertable = detail::can_insert_elements<T>()
&& !std::is_same<T, std::string>::value>
class config_option_impl : public config_option {
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment