Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use if constexpr in locale facets #5001

Merged
merged 4 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions stl/inc/xlocmon
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,6 @@ protected:
_Tidy();
}

template <class _Elem2>
void _Getvals(_Elem2, const lconv* _Ptr) { // get values
_Currencysign = _Maklocstr(
_International ? _Ptr->int_curr_symbol : _Ptr->currency_symbol, static_cast<_Elem2*>(nullptr), _Cvt);
_Plussign = _Maklocstr(4 < static_cast<unsigned int>(_Ptr->p_sign_posn) ? "" : _Ptr->positive_sign,
static_cast<_Elem2*>(nullptr), _Cvt);
_Minussign = _Maklocstr(4 < static_cast<unsigned int>(_Ptr->n_sign_posn) ? "-" : _Ptr->negative_sign,
static_cast<_Elem2*>(nullptr), _Cvt);
_Decimalpoint = _Maklocchr(_Ptr->mon_decimal_point[0], static_cast<_Elem2*>(nullptr), _Cvt);
_Kseparator = _Maklocchr(_Ptr->mon_thousands_sep[0], static_cast<_Elem2*>(nullptr), _Cvt);
}

void _Getvals(wchar_t, const lconv* _Ptr) { // get values
_Currencysign = reinterpret_cast<const _Elem*>(
_Maklocwcs(_International ? _Ptr->_W_int_curr_symbol : _Ptr->_W_currency_symbol));
_Plussign = reinterpret_cast<const _Elem*>(
_Maklocwcs(4 < static_cast<unsigned int>(_Ptr->p_sign_posn) ? L"" : _Ptr->_W_positive_sign));
_Minussign = reinterpret_cast<const _Elem*>(
_Maklocwcs(4 < static_cast<unsigned int>(_Ptr->n_sign_posn) ? L"-" : _Ptr->_W_negative_sign));
_Decimalpoint = static_cast<_Elem>(_Ptr->_W_mon_decimal_point[0]);
_Kseparator = static_cast<_Elem>(_Ptr->_W_mon_thousands_sep[0]);
}

void _Init(const _Locinfo& _Lobj, bool _Isdef = false) { // initialize from _Lobj
_Cvt = _Lobj._Getcvt();
const lconv* _Ptr = _Lobj._Getlconv();
Expand All @@ -140,7 +117,23 @@ protected:

_Tidy_guard<_Mpunct> _Guard{this};
_Grouping = _Maklocstr(_Ptr->mon_grouping, static_cast<char*>(nullptr), _Cvt);
_Getvals(_Elem{}, _Ptr);
if constexpr (is_same_v<_Elem, wchar_t>) {
_Currencysign = _Maklocwcs(_International ? _Ptr->_W_int_curr_symbol : _Ptr->_W_currency_symbol);
_Plussign = _Maklocwcs(4 < static_cast<unsigned int>(_Ptr->p_sign_posn) ? L"" : _Ptr->_W_positive_sign);
_Minussign = _Maklocwcs(4 < static_cast<unsigned int>(_Ptr->n_sign_posn) ? L"-" : _Ptr->_W_negative_sign);
_Decimalpoint = _Ptr->_W_mon_decimal_point[0];
_Kseparator = _Ptr->_W_mon_thousands_sep[0];
} else {
_Currencysign = _Maklocstr(
_International ? _Ptr->int_curr_symbol : _Ptr->currency_symbol, static_cast<_Elem*>(nullptr), _Cvt);
_Plussign = _Maklocstr(4 < static_cast<unsigned int>(_Ptr->p_sign_posn) ? "" : _Ptr->positive_sign,
static_cast<_Elem*>(nullptr), _Cvt);
_Minussign = _Maklocstr(4 < static_cast<unsigned int>(_Ptr->n_sign_posn) ? "-" : _Ptr->negative_sign,
static_cast<_Elem*>(nullptr), _Cvt);
_Decimalpoint = _Maklocchr(_Ptr->mon_decimal_point[0], static_cast<_Elem*>(nullptr), _Cvt);
_Kseparator = _Maklocchr(_Ptr->mon_thousands_sep[0], static_cast<_Elem*>(nullptr), _Cvt);
}

_Guard._Target = nullptr;

_Fracdigits = _International ? _Ptr->int_frac_digits : _Ptr->frac_digits;
Expand Down
22 changes: 8 additions & 14 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,6 @@ protected:
_END_LOCINFO()
}

template <class _Elem2>
void _Getvals(_Elem2, const lconv* _Ptr, _Locinfo::_Cvtvec _Cvt) { // get values
_Dp = _Maklocchr(_Ptr->decimal_point[0], static_cast<_Elem2*>(nullptr), _Cvt);
_Kseparator = _Maklocchr(_Ptr->thousands_sep[0], static_cast<_Elem2*>(nullptr), _Cvt);
}

void _Getvals(wchar_t, const lconv* _Ptr, _Locinfo::_Cvtvec) { // get values
_Dp = static_cast<_Elem>(_Ptr->_W_decimal_point[0]);
_Kseparator = static_cast<_Elem>(_Ptr->_W_thousands_sep[0]);
}

void _Init(const _Locinfo& _Lobj, bool _Isdef = false) { // initialize from _Lobj
const lconv* _Ptr = _Lobj._Getlconv();
_Locinfo::_Cvtvec _Cvt = _Lobj._Getcvt(); // conversion information
Expand All @@ -169,17 +158,22 @@ protected:
_Truename = nullptr;

_Tidy_guard<numpunct> _Guard{this};
_Grouping = _Maklocstr(_Isdef ? "" : _Ptr->grouping, static_cast<char*>(nullptr), _Lobj._Getcvt());
_Grouping = _Maklocstr(_Isdef ? "" : _Ptr->grouping, static_cast<char*>(nullptr), _Cvt);
_Falsename = _Maklocstr(_Lobj._Getfalse(), static_cast<_Elem*>(nullptr), _Cvt);
_Truename = _Maklocstr(_Lobj._Gettrue(), static_cast<_Elem*>(nullptr), _Cvt);
_Guard._Target = nullptr;

if (_Isdef) { // apply defaults for required facets
// _Grouping = _Maklocstr("", static_cast<char *>(nullptr), _Cvt);
_Dp = _Maklocchr('.', static_cast<_Elem*>(nullptr), _Cvt);
_Kseparator = _Maklocchr(',', static_cast<_Elem*>(nullptr), _Cvt);
} else {
_Getvals(_Elem{}, _Ptr, _Cvt);
if constexpr (is_same_v<_Elem, wchar_t>) {
_Dp = _Ptr->_W_decimal_point[0];
_Kseparator = _Ptr->_W_thousands_sep[0];
} else {
_Dp = _Maklocchr(_Ptr->decimal_point[0], static_cast<_Elem*>(nullptr), _Cvt);
_Kseparator = _Maklocchr(_Ptr->thousands_sep[0], static_cast<_Elem*>(nullptr), _Cvt);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xloctime
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected:
void __CLR_OR_THIS_CALL _Getvals(_Elem2, const _Locinfo& _Lobj) { // get values
_Cvt = _Lobj._Getcvt();

if (is_same_v<_Elem2, wchar_t>) {
if constexpr (is_same_v<_Elem2, wchar_t>) {
_Days = reinterpret_cast<const _Elem*>(_Maklocwcs(reinterpret_cast<const wchar_t*>(_Lobj._W_Getdays())));
_Months =
reinterpret_cast<const _Elem*>(_Maklocwcs(reinterpret_cast<const wchar_t*>(_Lobj._W_Getmonths())));
Expand Down