Namespaces
Variants
Views
Actions

Talk:cpp/string/char traits

From cppreference.com

The member types section says the types are implementation defined, but the preceding section says they're well defined, seems like the member types section should be removed --Ybab321 (talk) 03:21, 11 September 2023 (PDT)

The first part is about explicit specializations https://eel.is/c++draft/char.traits.specializations the second part is about general requirements (https://eel.is/c++draft/iostreams.limits.pos#1.sentence-2 and https://eel.is/c++draft/char.traits.typedefs ). Perhaps general part could be laid out better (on the other hand, nobody rolls their own iostreams for non-char types). --Cubbi (talk) 06:14, 11 September 2023 (PDT)
The standard doesn't say anything about the generic char_traits template. It specifies the character traits requirements (which apparently applies to every traits template argument), and it specifies the five char_traits specializations. But it doesn't seem to specify how the generic (unspecialized) char_traits template is defined. (Incidentally, libc++ deprecated the generic template last year [1] [2] and removed it last month [3].)
As it stands, I think we can't say anything more reasonable than 'implementation-defined' for the generic template (even though 'implementation-defined' isn't quite reasonable). --D41D8CD98F (talk) 07:17, 11 September 2023 (PDT)
Well, in a way they are right; https://eel.is/c++draft/char.traits#general-1 only says class template char_traits<charT> is defined, followed by the lengthy chapter on char traits requirements its specializations must satisfy, but doesn't describe a generic facility that could be instantiated with a user-defined CharT and automatically satisfy all those requirements. Maybe rephrase "Member types" as "Requirements on member types of user-defined specializations"? --Cubbi (talk) 08:03, 11 September 2023 (PDT)
User-defined specializations are not restricted as long as they are not used in places requiring CharTraits, we just need to forward the requirements on character traits to that page. We can simply use a long table (members as rows, specializations as columns) to list the five specializations' members' semantics on top of those required by CharTraits, removing the lists of member types and member functions currently in the page. --Xmcgcg (talk) 09:21, 11 September 2023 (PDT)
fair enough, except I worry if this means we'd lose separate pages for the standard traits' member functions - those are useful as link targets (or would be useful if we linked to them consistently: cpp/string/basic_string/find for example explains itself in terms of Traits::eq and Traits::length but without clickable links that would have been there landing on cpp/string/char_traits/length and cpp/string/char_traits/cmp) --Cubbi (talk) 10:08, 11 September 2023 (PDT)