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

IOFormatSaver #4104

Merged
merged 2 commits into from
Sep 8, 2024
Merged

IOFormatSaver #4104

merged 2 commits into from
Sep 8, 2024

Conversation

WeiqunZhang
Copy link
Member

Add a class that can be used to save and restore IO stream format in a RAII way. Below is an example.

auto& os = amrex::OutStream();
auto old_fill = os.fill();
auto old_flags = os.flags();
auto old_precision = os.precision();
auto old_width = os.width();

{
    IOFormatSaver iofmtsaver(os);

    os << std::setfill('x');
    os << std::left;
    os << std::setprecision(4);
    os << std::setw(111);
}

AMREX_ALWAYS_ASSERT(old_fill == os.fill());
AMREX_ALWAYS_ASSERT(old_flags == os.flags());
AMREX_ALWAYS_ASSERT(old_precision == os.precision());
AMREX_ALWAYS_ASSERT(old_width == os.width());

Add a class that can be used to save and restore IO stream format in a RAII
way. Below is an example.

    auto& os = amrex::OutStream();
    auto old_fill = os.fill();
    auto old_flags = os.flags();
    auto old_precision = os.precision();
    auto old_width = os.width();

    {
        IOFormatSaver iofmtsaver(os);

        os << std::setfill('x');
        os << std::left;
        os << std::setprecision(4);
        os << std::setw(111);
    }

    AMREX_ALWAYS_ASSERT(old_fill == os.fill());
    AMREX_ALWAYS_ASSERT(old_flags == os.flags());
    AMREX_ALWAYS_ASSERT(old_precision == os.precision());
    AMREX_ALWAYS_ASSERT(old_width == os.width());
@WeiqunZhang WeiqunZhang enabled auto-merge (squash) September 8, 2024 14:52
@WeiqunZhang WeiqunZhang merged commit 8a5a989 into AMReX-Codes:development Sep 8, 2024
59 checks passed
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