fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.9k stars 2.43k forks source link

xchar.h extra dependencies #3940

Closed alabuzhev closed 2 months ago

alabuzhev commented 2 months ago

The library is modular, which is awesome:

https://fmt.dev/latest/api.html

fmt/ranges.h: formatting of ranges and tuples fmt/color.h: terminal color and text style fmt/xchar.h: optional wchar_t support

I don't care about formatting of ranges and tuples or terminal color, so I don't include the corresponding headers. I do need wchar_t support, so I include xchar.h. It's been like that for years.

However, since 2e5b14bf603429a08ab9480bcd1fd537a2fe8f16 xchar.h unconditionally includes color.h. And since 50565f9853926501bd1c9bda07c6a98f4d940691 xchar.h unconditionally includes ranges.h.

It's probably not such a big deal, but "don't pay for what you don't use" is a thing, same as extra 50 KB of templates. Maybe there's a way to avoid that? E.g. wrap range- and color-specific code in xchar.h in #ifdef FMT_RANGES_H_ / #ifdef FMT_COLOR_H_, so that it's active only if the user opted in by including the corresponding headers manually first?

vitaut commented 2 months ago

Thanks for the suggestion but depending on the include order would be too error prone. Templates themselves shouldn't add much overhead if you don't use them so I wouldn't worry too much about any of that and, for example, <format> provides range formatting out of the box.