C++ Logo

std-proposals

Advanced search

[std-proposals] Adding formatter for std::fpos

From: 梁家铭 <liangjiaming_at_[hidden]>
Date: Sun, 21 Jul 2024 19:00:00 +0800 (GMT+08:00)
It's quite frustrating that code below works:


std::stringstream s{"123"};
std::cout << s.tellg();


But code below doesn't:


std::stringstream s{"123"};
std::println("{}", s.tellg());



The reason lies in that `std::fpos` can be implicitly converted to `std::streamoff`, which is one of the signed integer types (and overloaded operator<< will match it). But it doesn't support `std::formatter` directly, so we have to code like:


std::println("{}", s.tellg() - std::streampos{});
// or
std::println("{}", (std::streamoff)s.tellg());




I'd like to post a small proposal for adding std::formatter for it :).








Received on 2024-07-21 11:00:11