| 1218 | |
| 1219 | template <class T> |
| 1220 | typename std::enable_if<!std::is_floating_point<T>::value |
| 1221 | && std::is_signed<T>::value, |
| 1222 | option<T>>::type |
| 1223 | get_impl(const std::shared_ptr<base>& elem) |
| 1224 | { |
| 1225 | if (auto v = elem->as<int64_t>()) |
| 1226 | { |
| 1227 | if (v->get() < (std::numeric_limits<T>::min)()) |
| 1228 | throw std::underflow_error{ |
| 1229 | "T cannot represent the value requested in get"}; |
| 1230 | |
| 1231 | if (v->get() > (std::numeric_limits<T>::max)()) |
| 1232 | throw std::overflow_error{ |
| 1233 | "T cannot represent the value requested in get"}; |
| 1234 | |
| 1235 | return {static_cast<T>(v->get())}; |
| 1236 | } |
| 1237 | else |
| 1238 | { |
| 1239 | return {}; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | template <class T> |
| 1244 | typename std::enable_if<!std::is_same<T, bool>::value |