I have created a custom locale facet by specializing std::ctype
for int32_t
, to accommodate my std::basic_string<int32_t>
.
namespace std
{
template <>
class ctype<std::int32_t> : public std::ctype_base
{
public:
static std::locale::id id;
// other members
};
}
However, I find that this facet gets ignored completely by std::locale::ctype
when reusing facets from another locale:
using my_ctype = std::ctype<int32_t>;
std::locale custom_loc(std::locale::classic(), new my_ctype());
bool a = std::has_facet<my_ctype>(custom_loc); // true
std::locale with_original_ctype(std::locale(""), custom_loc, std::locale::ctype);
bool b = std::has_facet<my_ctype>(with_original_ctype); // false
std::locale everything_replaced(custom_loc, std::locale(""), std::locale::all);
bool c = std::has_facet<my_ctype>(everything_replaced); // true
At least on MSVC, even though with_original_ctype
should reuse all std::locale::ctype
facets from custom_loc
, it is missing my_ctype
. Worse even, everything_replaced
, despite being constructed with std::locale::all
taken from std::locale("")
, still retains the custom facet.
How do I make the facet be correctly interpreted as being in the category std::locale::ctype
?