Skip to content

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