Skip to content

Commit

Permalink
add from_chars(s, fmt::overflow_checked_<T> *) for generic code
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Jun 20, 2024
1 parent 1cf2a75 commit f9e970a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

- Add `bool from_chars(csubstr s, fmt::overflow_checked_<T> *wrapper)`. There was already is a function receiving `&wrapper`, but `*wrapper` was missing for use with generic code.

11 changes: 10 additions & 1 deletion src/c4/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ to_chars(substr buf, fmt::integral_padded_<T> fmt)
return utoa(buf, fmt.val, fmt.radix, fmt.num_digits);
}

/** read an format an integer unsigned type
/** read an integer type, detecting overflow (returns false on overflow)
* @ingroup doc_from_chars */
template<class T>
C4_ALWAYS_INLINE bool from_chars(csubstr s, fmt::overflow_checked_<T> wrapper)
Expand All @@ -332,6 +332,15 @@ C4_ALWAYS_INLINE bool from_chars(csubstr s, fmt::overflow_checked_<T> wrapper)
return atox(s, wrapper.val);
return false;
}
/** read an integer type, detecting overflow (returns false on overflow)
* @ingroup doc_from_chars */
template<class T>
C4_ALWAYS_INLINE bool from_chars(csubstr s, fmt::overflow_checked_<T> *wrapper)
{
if(C4_LIKELY(!overflows<T>(s)))
return atox(s, wrapper->val);
return false;
}


//-----------------------------------------------------------------------------
Expand Down

0 comments on commit f9e970a

Please sign in to comment.