Skip to content

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

Merged
vitaut merged 13 commits into
fmtlib:masterfrom
alexezeder:feature/formatting_at_compile_time
Nov 29, 2020
Merged

vitaut merged 13 commits into
fmtlib:masterfrom
alexezeder:feature/formatting_at_compile_time

Conversation

@alexezeder

@alexezeder alexezeder commented Nov 14, 2020

Copy link
Copy Markdown
Contributor

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

alexezeder commented Nov 14, 2020

Copy link
Copy Markdown
Contributor Author

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)

Comment thread include/fmt/format.h Outdated
Comment thread test/CMakeLists.txt Outdated
@alexezeder

alexezeder commented Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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

@alexezeder
alexezeder requested a review from vitaut November 19, 2020 19:03
Comment thread include/fmt/core.h Outdated
Comment thread include/fmt/core.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/core.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
@alexezeder
alexezeder requested a review from vitaut November 26, 2020 19:34
Comment thread include/fmt/core.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h Outdated
Comment thread include/fmt/format.h
Comment thread include/fmt/format.h Outdated
* `FMT_CONSTEXPR20` defined as `inline` when it cannot be `constexpr`
* rename `count_digits_trivial()` to `count_digits_fallback()`
@alexezeder

Copy link
Copy Markdown
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.

@alexezeder
alexezeder requested a review from vitaut November 28, 2020 20:10
Comment thread test/compile-test.cc Outdated

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

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.

@alexezeder
alexezeder requested a review from vitaut November 28, 2020 23:32
Comment thread test/compile-test.cc
@alexezeder
alexezeder requested a review from vitaut November 29, 2020 00:42
Comment thread test/compile-test.cc Outdated
@alexezeder

Copy link
Copy Markdown
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.

@alexezeder
alexezeder requested a review from vitaut November 29, 2020 16:01
@vitaut
vitaut merged commit dac753b into fmtlib:master Nov 29, 2020
@vitaut

vitaut commented Nov 29, 2020

Copy link
Copy Markdown
Contributor

Merged, thanks!

@alexezeder

Copy link
Copy Markdown
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