views:

31

answers:

1

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?

+2  A: 

Seeing how the standard library's isspace() is actually std::isspace(charT, const std::locale&), I would think it would follow the principle of the least surprise if your trim whitespace functions also took const locale&.

But what's stopping you from allowing both?

Cubbi