Skip to content

Commit

Permalink
Member function pointer -> function_ptr in integer_ and float_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Nov 11, 2023
1 parent 5b85c29 commit 9130739
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
36 changes: 22 additions & 14 deletions src/scn/impl/reader/float_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,15 @@ namespace scn {
read_default(Range&& range, T& value, detail::locale_ref loc)
{
SCN_UNUSED(loc);
using range_nocvref_t = detail::remove_cvref_t<Range>;

float_reader<CharT> rd{};
return read_impl(range, rd,
&float_reader<CharT>::template read_source<
detail::remove_cvref_t<Range>>,
value);
return read_impl<range_nocvref_t>(
range, rd,
[](float_reader<CharT>& r, auto&&... args) {
return r.read_source(SCN_FWD(args)...);
},
value);
}

template <typename Range, typename T>
Expand All @@ -620,35 +623,40 @@ namespace scn {
T& value,
detail::locale_ref loc)
{
using range_nocvref_t = detail::remove_cvref_t<Range>;
float_reader<CharT> rd{get_options(specs)};

#if !SCN_DISABLE_LOCALE
if (specs.localized) {
return read_impl(
return read_impl<range_nocvref_t>(
range, rd,
&float_reader<CharT>::template read_source_localized<
detail::remove_cvref_t<Range>>,
[](float_reader<CharT>& r, auto&&... args) {
return r.read_source_localized(SCN_FWD(args)...);
},
value, loc);
}
#endif

return read_impl(range, rd,
&float_reader<CharT>::template read_source<
detail::remove_cvref_t<Range>>,
value);
return read_impl<range_nocvref_t>(
range, rd,
[](float_reader<CharT>& r, auto&&... args) {
return r.read_source(SCN_FWD(args)...);
},
value);
}

private:
template <typename Range>
using read_source_callback_type =
scan_expected<ranges::iterator_t<Range>> (
float_reader<CharT>::*)(Range, detail::locale_ref);
scan_expected<ranges::iterator_t<Range>>(float_reader<CharT>&,
Range,
detail::locale_ref);

template <typename Range, typename T>
scan_expected<ranges::iterator_t<Range>> read_impl(
Range range,
float_reader<CharT>& rd,
read_source_callback_type<Range> read_source_cb,
function_ref<read_source_callback_type<Range>> read_source_cb,
T& value,
detail::locale_ref loc = {})
{
Expand Down
43 changes: 27 additions & 16 deletions src/scn/impl/reader/integer_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,23 @@ namespace scn {
detail::check_int_type_specs(specs, eh);
}

template <typename>
struct debug;

template <typename Range, typename T>
scan_expected<simple_borrowed_iterator_t<Range>>
read_default(Range&& range, T& value, detail::locale_ref loc)
{
using range_nocvref_t = detail::remove_cvref_t<Range>;
SCN_UNUSED(loc);

integer_reader<CharT> rd{detail::tag_type<T>{}};
return read_impl(range, rd,
&integer_reader<CharT>::template read_source<
detail::remove_cvref_t<Range>>,
value, loc);
return read_impl<range_nocvref_t>(
range, rd,
[](integer_reader<CharT>& r, auto&&... args) {
return r.read_source(SCN_FWD(args)...);
},
value, loc);
}

template <typename Range, typename T>
Expand All @@ -471,40 +477,45 @@ namespace scn {
T& value,
detail::locale_ref loc)
{
using range_nocvref_t = detail::remove_cvref_t<Range>;
auto rd = get_reader_from_specs(specs);

#if !SCN_DISABLE_LOCALE
if (specs.localized) {
return read_impl(
return read_impl<range_nocvref_t>(
range, rd,
&integer_reader<CharT>::template read_source_localized<
detail::remove_cvref_t<Range>>,
[](integer_reader<CharT>& r, auto&&... args) {
return r.read_source_localized(SCN_FWD(args)...);
},
value, loc);
}
#endif

return read_impl(range, rd,
&integer_reader<CharT>::template read_source<
detail::remove_cvref_t<Range>>,
value, loc);
return read_impl<range_nocvref_t>(
range, rd,
[](integer_reader<CharT>& r, auto&&... args) {
return r.read_source(SCN_FWD(args)...);
},
value, loc);
}

private:
template <typename Range>
using read_source_callback_type =
scan_expected<ranges::iterator_t<Range>> (
integer_reader<CharT>::*)(Range, bool, detail::locale_ref);
scan_expected<ranges::iterator_t<Range>>(integer_reader<CharT>&,
Range,
bool,
detail::locale_ref);

template <typename Range, typename T>
scan_expected<ranges::iterator_t<Range>> read_impl(
Range range,
integer_reader<CharT>& rd,
read_source_callback_type<Range> read_source_cb,
function_ref<read_source_callback_type<Range>> read_source_cb,
T& value,
detail::locale_ref loc = {})
{
if (auto r = std::invoke(read_source_cb, rd, range,
std::is_signed_v<T>, loc);
if (auto r = read_source_cb(rd, range, value, loc);
SCN_UNLIKELY(!r)) {
return unexpected(r.error());
}
Expand Down

0 comments on commit 9130739

Please sign in to comment.