Post B1dpFksx97taLFlgKe by vitaut@mastodon.social
 (DIR) More posts by vitaut@mastodon.social
 (DIR) Post #B1cLTZKPij1qllK7KS by vitaut@mastodon.social
       2025-12-25T19:39:27Z
       
       0 likes, 0 repeats
       
       For comparison, this is how std::to_chars is supposed to be used:  char buf[25];  std::to_chars_result result =    std::to_chars(buf, buf + sizeof(buf), 6.62607015e-34);  if (result.ec != std::errc()) {    // ...  }
       
 (DIR) Post #B1cLTaboxUXyk2TX6G by divVerent@social.vivaldi.net
       2025-12-25T20:04:40Z
       
       0 likes, 0 repeats
       
       @vitaut TBH I never saw the point of `std::to_chars`.If performance is paramount, often the C ways are better anyway. If performance doesn't matter, OTOH:```(std::ostringstream() << 6.62607015e-34).str()```In later standards, std::format also provides a good alternative here.
       
 (DIR) Post #B1cMIzpqvYQlkSYEwC by vitaut@mastodon.social
       2025-12-25T20:13:59Z
       
       0 likes, 0 repeats
       
       @divVerent there was no standard alternative to get the shortest representation in C or C++ before it
       
 (DIR) Post #B1d8qcXYq7TH965v5E by divVerent@social.vivaldi.net
       2025-12-26T05:18:00Z
       
       0 likes, 0 repeats
       
       @vitaut True, in the past I have had to use nonstandard methods for that.Having said that, std::to_chars is just such a horrible API. Can't they at least return a std::string?
       
 (DIR) Post #B1dpFksx97taLFlgKe by vitaut@mastodon.social
       2025-12-26T13:13:05Z
       
       0 likes, 0 repeats
       
       @divVerent I actually fixed to_string to do exactly that https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2587r2.html