Is cout Guaranteed to Have the ctype<char> facet?
Asked Answered
L

1

4

Given: auto foo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"s I can convert all the characters to lowercase by:

use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size()));

Live Example

But this depends upon cout.getloc() containing the ctype<char> facet.

Presuming that I'm using an unmodified cout can I assume that cout.getloc() will contain the facet ctype<char> or do I need to confirm this before use with:

has_facet<ctype<char>>(cout.getloc())
Leyes answered 25/5, 2016 at 12:12 Comment(8)
FYI I closed that question as a dupe. You may want to move your answer to the target instead of having it on the linked to question.Chun
@Chun Man the Roomba got to that fast. I gotta hurry up and get to 10k so I can see my answers on deleted questions! Anyway, I've typed something up from memory on the correct question: https://mcmap.net/q/54349/-why-can-39-t-quot-transform-s-begin-s-end-s-begin-tolower-quot-be-complied-successfully Thanks for the heads up.Leyes
Here(pastebin-link) is the source of your answerChun
@Chun Thanks, I appreciate you grabbing that for me! I've used it to update the answer, eliminating the link to: stackoverflow.com/a/37435426/2642059Leyes
hm guys the question linked gives a 404, "removed from stackoverflow by reasons of moderation"Goon
@Goon Sounds like we both need to get to 10K so we can see that answer! I've updated the question with the relevant sections from my answer there.Leyes
@Chun HAHA! Finally made it to 10K! I can see the question again! Who knows what mayhem I can wreck with this new-found power!Leyes
@JonathanMee Congrats, Now you can be power drunk like the rest of us ;-)Chun
G
3

From cppreference:

Each locale constructed in a C++ program holds at least the following standard facets [...]:

  1. std::ctype<char>
  2. ...

Any locale, meaning even locales not of the cout object will support std::ctype<char>.

Goon answered 25/5, 2016 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.