New ostream() returns dynamic buffer output stream (API Change):

This eliminates beast::write output for dynamic buffers and replaces
it with the function ostream() that wraps a caller provided dynamic
buffer and returns the result as a std::ostream derived object.
Callers may now produce formatted output into any object meeting the
requirements of DynamicBuffer using operator<< and the standard stream
modifiers such as std::endl.

This new technique is more efficient, as implementations of operator<<
can now write directly into the output using std::ostream::write and
std::ostream::put.

Example of use:

  beast::streambuf sb;
  beast::ostream(sb) << "Hello, world!" << std::endl;
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:16 -07:00
parent 3f58d81fc4
commit 3add5f293c
16 changed files with 373 additions and 337 deletions
+32
View File
@@ -0,0 +1,32 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/core/ostream.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
#include <ostream>
#include <beast/core/to_string.hpp>
namespace beast {
class ostream_test : public beast::unit_test::suite
{
public:
void run() override
{
streambuf sb;
ostream(sb) << "Hello, world!\n";
BEAST_EXPECT(to_string(sb.data()) == "Hello, world!\n");
}
};
BEAST_DEFINE_TESTSUITE(ostream,core,beast);
} // beast