Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basics of formatting at compile-time based on compile-time API #2019

Merged
merged 13 commits into from
Nov 29, 2020

Conversation

alexezeder
Copy link
Contributor

@alexezeder alexezeder commented Nov 14, 2020

I need to say that this PR does not introduce fully-functioning formatting via {fmt} at compile-time. By fully-functioning I mean that I handled only a few cases (bool, integer, string) of the entire functionality of this library.

This PR based on compile-time API from compile.h. This forces end-users to use FMT_COMPILE macro in cases when formatting should happen at compile-time.

  • new compile-time formatting tests added into compile-test test case, available only if C++ standard is greater or equal to C++20
  • new FMT_CONSTEXPR20 macro definition added
  • new is_constant_evaluated() function in fmt::details namespace added, that invokes std::is_constant_evaluated() if std library has it, otherwise falls back to returning false

What functionality of the library is not available at compile-time with this PR:

  • pointers formatting - std::bit_cast is not available yet, so it's not possible yet
  • floating-point numbers formatting - looks like it's possible, but takes some time
  • format specifications (padding, precision, etc.) - haven't tried, takes some time
  • colors, locales, other functionality I'm not aware of - haven't tried, takes some time

@alexezeder
Copy link
Contributor Author

alexezeder commented Nov 14, 2020

Since the current CI configuration lacks C++ standards other than C++11 and I was eager to know if it compiles with standards other than C++11, I prepared a special branch to check it on CI, forgot to mention that it has only specific to Linux changes in workflow
https://github.com/alexezeder/fmt/actions/runs/363499597 (looks like g++-10 does not support C++20, so ignore it)

include/fmt/format.h Outdated Show resolved Hide resolved
test/CMakeLists.txt Outdated Show resolved Hide resolved
@alexezeder
Copy link
Contributor Author

alexezeder commented Nov 19, 2020

Looks like even gcc-10 with 20 standard works now. Not sure why didn't it work for the first time...

include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
* `FMT_CONSTEXPR20` defined as `inline` when it cannot be `constexpr`
* rename `count_digits_trivial()` to `count_digits_fallback()`
@alexezeder
Copy link
Contributor Author

🤨 I don't know what exactly happened to doc build, but it's was not able to get some dependencies and it's the only one that failed.

test/compile-test.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just one small suggestion to simplify tests.

test/compile-test.cc Outdated Show resolved Hide resolved
@alexezeder
Copy link
Contributor Author

@vitaut I also remind you that there is a question from me without an answer (#2019 (comment)), this is why I didn't resolve the thread - I fulfilled only one of your points. count_digits_fallback still has template argument.

@vitaut vitaut merged commit dac753b into fmtlib:master Nov 29, 2020
@vitaut
Copy link
Contributor

vitaut commented Nov 29, 2020

Merged, thanks!

@alexezeder
Copy link
Contributor Author

Since we have the base now, I will try to cover the remaining functionality of the library by following PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants