@@ -199,21 +199,49 @@ using namespace std::string_view_literals;
199199 return expect_uint (callback, base);
200200 }
201201
202+ template <derived_from_specialization_of<type_safe::strong_typedef> T, typename AsT = type_safe::underlying_type<T>>
203+ NodeCallback auto expect_strong_typedef (callback_t <T>& callback, int base = 10 ) {
204+ if constexpr (std::unsigned_integral<AsT>) {
205+ return expect_uint64 (
206+ [callback](uint64_t val) mutable -> bool {
207+ if (val <= static_cast <uint64_t >(std::numeric_limits<AsT>::max ())) {
208+ return callback (T (val));
209+ }
210+ spdlog::error_s (
211+ " Invalid uint: {} (valid range: [0, {}])" , val,
212+ static_cast <uint64_t >(std::numeric_limits<AsT>::max ())
213+ );
214+ return false ;
215+ },
216+ base
217+ );
218+ } else {
219+ return expect_int64 (
220+ [callback](int64_t val) mutable -> bool {
221+ if (val >= static_cast <int64_t >(std::numeric_limits<AsT>::min ()) &&
222+ val <= static_cast <int64_t >(std::numeric_limits<AsT>::max ())) {
223+ return callback (T (val));
224+ }
225+ spdlog::error_s (
226+ " Invalid int: {} (valid range: [{}, {}])" , val,
227+ static_cast <int64_t >(std::numeric_limits<AsT>::min ()),
228+ static_cast <int64_t >(std::numeric_limits<AsT>::max ())
229+ );
230+ return false ;
231+ },
232+ base
233+ );
234+ }
235+ }
236+ template <derived_from_specialization_of<type_safe::strong_typedef> T, typename AsT = type_safe::underlying_type<T>>
237+ NodeCallback auto expect_strong_typedef (callback_t <T>&& callback, int base = 10 ) {
238+ return expect_strong_typedef<T, AsT>(callback, base);
239+ }
240+
202241 template <derived_from_specialization_of<type_safe::strong_typedef> T>
203242 requires std::unsigned_integral<type_safe::underlying_type<T>>
204243 NodeCallback auto expect_index (callback_t <T>& callback, int base = 10 ) {
205- using underlying_type = type_safe::underlying_type<T>;
206-
207- return expect_uint64 ([callback](uint64_t val) mutable -> bool {
208- if (val <= static_cast <uint64_t >(std::numeric_limits<underlying_type>::max ())) {
209- return callback (T (val));
210- }
211- spdlog::error_s (
212- " Invalid uint: {} (valid range: [0, {}])" ,
213- val, static_cast <uint64_t >(std::numeric_limits<underlying_type>::max ())
214- );
215- return false ;
216- }, base);
244+ return expect_strong_typedef<T>(callback, base);
217245 }
218246 template <derived_from_specialization_of<type_safe::strong_typedef> T>
219247 requires std::unsigned_integral<type_safe::underlying_type<T>>
0 commit comments