Skip to content

WarnManager.cpp: simplify an expression using std::format (C++20 feature) - #7230

Closed
lucafedeli88 wants to merge 1 commit into
BLAST-WarpX:developmentfrom
lucafedeli88:ablastr_use_format
Closed

WarnManager.cpp: simplify an expression using std::format (C++20 feature)#7230
lucafedeli88 wants to merge 1 commit into
BLAST-WarpX:developmentfrom
lucafedeli88:ablastr_use_format

Conversation

@lucafedeli88

Copy link
Copy Markdown
Member

C++20 has introduced a [text formatting library](see https://en.cppreference.com/cpp/utility/format) that greatly simplifies certain expressions.

This PR exemplifies this new feature by changing the expression :

                "["
                + std::string(abl_msg_logger::PriorityToString(msg_priority))
                + "]["
                + topic
                + "] "
                + text));

into

                std::format("[{}][{}] {}",
                    abl_msg_logger::PriorityToString(msg_priority), topic, text)));

I've verified that, after this substitution, the warning logger produces a text message identical to the one of the test presented here: https://warpx.readthedocs.io/en/latest/developers/warning_logger.html .

If no issues are reported, I would like to expand the usage of std::format in WarpX.

@lucafedeli88 lucafedeli88 added the cleaning Clean code, improve readability label Sep 1, 2026
@lucafedeli88

Copy link
Copy Markdown
Member Author

I am closing this, because one of the compiler combinations that we want to support (nvcc with gcc v11.4.0 as the host compiler) does not support std::format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleaning Clean code, improve readability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant