Timeline for Implementing std::format - Part 3
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 3, 2021 at 21:59 | comment | added | JDługosz | ... to decide if it's a stringline thing or some other pointer where you just print the pointer's address. Messing with stuff beyond your skill level is how you grow. "messing around" sure beats being beyond your skill level in assigned work with deadlines and customers! | |
| Nov 3, 2021 at 21:58 | comment | added | JDługosz |
@upkajdt forget enable_if if you have a current compiler. Use requires which is a direct language feature for doing this, and much easier to use. Instead of the template constrained to anything that's not std::string, it should be anything that's trivially copyable. That still leaves char* and variations that you want funneled to be handled as a string... A "better" template match is a function that specifically takes pointers. So foo (T*) will match with T as char or const char as well as unsigned char etc. This pointer form can use constexpr if in the body...
|
|
| Nov 3, 2021 at 19:33 | comment | added | jdt | Something like this might work, but now I'm messing with stuff that is way beyond my skill level =) godbolt.org/z/T1nPKPf9z | |
| Nov 3, 2021 at 19:03 | comment | added | jdt | This works until you have the generic function template: godbolt.org/z/95K35dWvq. | |
| Nov 3, 2021 at 18:17 | comment | added | JDługosz |
@upkajdt godbolt.org/z/Yj8rTWhfr You should not have to declare the other two overloads at all. I think your problem is that you are defining them to call the string_view version, rather than just defining the string_view form only.
|
|
| Nov 3, 2021 at 18:04 | comment | added | jdt | This seems to work, but it is ugly TIO | |
| Nov 3, 2021 at 17:52 | comment | added | JDługosz |
@upkajdt then there's something wrong, because we normally pass both std::string objects and literal lexical strings "like this" to functions declared to take std::string_view.
|
|
| Nov 3, 2021 at 17:49 | comment | added | jdt |
Thanks for your valuable insights! I'm not sure if I'm implementing this wrong, but the string_view overload does not seem to handle std::string and const char*: TIO
|
|
| Nov 3, 2021 at 16:14 | history | edited | JDługosz | CC BY-SA 4.0 |
added 371 characters in body
|
| Nov 3, 2021 at 16:03 | history | answered | JDługosz | CC BY-SA 4.0 |