DAW JSON Link
Loading...
Searching...
No Matches
daw_writable_output_fwd.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
12
13#include <daw/daw_traits.h>
14
15#include <cstddef>
16#include <type_traits>
17#include <utility>
18
19namespace daw::json {
20 inline namespace DAW_JSON_VER {
21 namespace concepts {
28 template<typename, typename = void>
29 struct writable_output_trait : std::false_type {};
30
31 template<typename T>
32 DAW_CPP20_CONCEPT is_writable_output_type_v =
34 } // namespace concepts
35
36 template<typename WritableOutput, typename... StringViews>
37 constexpr WritableOutput &write_output( WritableOutput &out,
38 StringViews const &...svs ) {
39 concepts::writable_output_trait<WritableOutput>::write( out, svs... );
40 return out;
41 }
42
43 template<typename WritableOutput, typename CharT>
44 constexpr WritableOutput &put_output( WritableOutput &out, CharT c ) {
45 concepts::writable_output_trait<WritableOutput>::put( out, c );
46 return out;
47 }
48
49 namespace concepts {
52 template<typename WritableOutput, typename = void>
53 inline constexpr bool has_output_reserve_v = false;
54
55 template<typename WritableOutput>
56 inline constexpr bool has_output_reserve_v<
57 WritableOutput,
59 std::declval<WritableOutput &>( ), std::size_t{ } ) )>> = true;
60 } // namespace concepts
61
64 template<typename WritableOutput>
65 constexpr WritableOutput &reserve_output( WritableOutput &out,
66 std::size_t n ) {
67 if constexpr( concepts::has_output_reserve_v<WritableOutput> ) {
68 concepts::writable_output_trait<WritableOutput>::reserve( out, n );
69 }
70 return out;
71 }
72 } // namespace DAW_JSON_VER
73} // namespace daw::json
constexpr bool has_output_reserve_v
Writable outputs may optionally have a static reserve( T &, std::size_t ) to make room for that many ...
constexpr WritableOutput & put_output(WritableOutput &out, CharT c)
constexpr WritableOutput & write_output(WritableOutput &out, StringViews const &...svs)
constexpr WritableOutput & reserve_output(WritableOutput &out, std::size_t n)
Hint that about n more bytes will be written. Outputs without a reserve ignore it,...
string_writer grows its string with resize_and_overwrite, leaving the new bytes uninitialized,...
Writable output models write/putc methods to allow efficient output to buffers/FILE streams/ostreams/...
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20