Skip to content

Commit d5cb217

Browse files
committed
containers can be written to ostream
1 parent 4b3f6ff commit d5cb217

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

include/boost/http_proto/fields_view_base.hpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
#include <boost/http_proto/detail/config.hpp>
1515
#include <boost/http_proto/detail/header.hpp>
16+
17+
#include <boost/core/detail/string_view.hpp>
1618
#include <boost/url/grammar/recycled.hpp>
1719
#include <boost/url/grammar/type_traits.hpp>
18-
#include <boost/core/detail/string_view.hpp>
20+
21+
#include <iosfwd>
1922
#include <string>
2023

2124
namespace boost {
@@ -429,6 +432,42 @@ class fields_view_base
429432
core::string_view name) const noexcept;
430433
};
431434

435+
/** Format the container to the output stream
436+
437+
This function serializes the container to
438+
the specified output stream.
439+
440+
@par Example
441+
@code
442+
request req;
443+
std::stringstream ss;
444+
ss << req;
445+
assert( ss.str() == "GET / HTTP/1.1\r\n\r\n" );
446+
@endcode
447+
448+
@par Effects
449+
@code
450+
return os << f.buffer();
451+
@endcode
452+
453+
@par Complexity
454+
Linear in `f.buffer().size()`
455+
456+
@par Exception Safety
457+
Basic guarantee.
458+
459+
@return A reference to the output stream, for chaining
460+
461+
@param os The output stream to write to.
462+
463+
@param f The container to write.
464+
*/
465+
BOOST_HTTP_PROTO_DECL
466+
std::ostream&
467+
operator<<(
468+
std::ostream& os,
469+
const fields_view_base& f);
470+
432471
} // http_proto
433472
} // boost
434473

src/fields_view_base.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,5 +383,13 @@ find_all(
383383

384384
//------------------------------------------------
385385

386+
std::ostream&
387+
operator<<(
388+
std::ostream& os,
389+
const fields_view_base& f)
390+
{
391+
return os << f.buffer();
392+
}
393+
386394
} // http_proto
387395
} // boost

0 commit comments

Comments
 (0)