[Copied from SO][7]. (Looking at the the [FAQ][8], I'd say it is on topic here.)

* A purpose — a task to accomplish, a user story

➔ Make `iostreams` less verbose to use and prevent errors wrt. stickiness / non stickiness of flags.

* Some objective requirements — a minimum set of features

➔ Provide a wrapper function for each of the [format flags][9] as well as the [fill, precision and width][10] options.

---------------

Since raw use of the [iomanip][1] stream modifiers is a) verbose and b) error prone ([sticky vs. non-sticky][2], etc.), for user defined types, all that stuff can be hidden in the default `operator<<` ... as [shown here, for example][3].

However, when formatting built-in types (even from within a user defined operator), it would be much more convenient (IMHO) to use an approach similar to [`std::quoted`][4]<sup>(beware C++14)</sup>, where the data is wrapped in a function call that returns a temporary object that sets + resets the appropriate flags.

Essentially, instead of [writing][5]:

    std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n";

you would hypothetically write:

    using namespace shorter;
    std::cout << precis(2, fixed(1.234556)) << "\n";

As the example shows, combination of flags could get tricky and I'm sure the devil is in the details, so I was wondering whether there is any prior art / exiting helper library that tries to address "chevron hell". :-)

* Is there any existing library addressing this?
* What are the technical pitfalls here, if one wants to come up with a set of helpers oneself?

Specifically, this question is not about any kind of "type safe format string" (like Boost.Format offers).

I'm also not asking for a "best" library, I'm asking about *any* library doing this for normal ostreams. (Because I was not able to find any.)

For example, the [write API of C++ Format][6] does something like this, but it doesn't do it for std::iostreams, but for the library's "stream" type:

    MemoryWriter out;
    out << pad(hex(0xcafe), 8, '0');


  [1]: http://en.cppreference.com/w/cpp/header/iomanip
  [2]: https://stackoverflow.com/questions/1532640/which-iomanip-manipulators-are-sticky
  [3]: https://stackoverflow.com/questions/5328411/effective-use-of-c-iomanip-library
  [4]: http://en.cppreference.com/w/cpp/io/manip/quoted
  [5]: https://github.com/cppformat/cppformat#iostreams
  [6]: http://cppformat.readthedocs.org/en/stable/reference.html#write-api


  [7]: https://stackoverflow.com/questions/28418943/ready-to-use-c-iomanip-wrappers
  [8]: https://softwarerecs.stackexchange.com/help/on-topic
  [9]: http://en.cppreference.com/w/cpp/io/ios_base/fmtflags
  [10]: http://en.cppreference.com/w/cpp/header/iomanip