Recently I wrote a family of functions for trimming leading and trailing whitespace off of an input string. As the concept of "whitespace" is locale-dependent, I realized that I would need to either pass in a const std::ctype<char_t>
reference or a const std::locale
reference and call std::use_facet<std::ctype<char_t> >
on the const std::locale
object.
In my library, I decided upon passing a const std::locale
reference because I figured that the std::locale
object encapsulated the entirety of locale information, and that std::use_facet
was the library-specific mechanism of access. However, I then started wondering whether it might be a better choice (perhaps it is more common?) to pass in the const std::ctype<char_t>
reference for direct use by the functions.
Which is more common in locale-sensitive libraries: passing the const std::locale
reference or const-references to the needed facets?