DAW JSON Link
Loading...
Searching...
No Matches
daw_writable_output_details.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
14
15#include <daw/daw_algorithm.h>
16#include <daw/daw_character_traits.h>
17#include <daw/daw_string_view.h>
18
19#include <cstddef>
20#include <cstdio>
21#include <type_traits>
22#include <utility>
23
24namespace daw::json {
25 inline namespace DAW_JSON_VER {
26 namespace concepts::writeable_output_details {
27 template<typename T>
28 constexpr T *copy_to_buffer( T *buff, daw::string_view source ) {
29 if( DAW_IS_CONSTANT_EVALUATED_COMPAT( ) ) {
30 daw::algorithm::transform_n( source.data( ),
31 buff,
32 source.size( ),
33 []( auto c )
35 return static_cast<T>( c );
36 } );
37 } else {
38 memcpy( buff, source.data( ), source.size( ) );
39 }
40 return buff + source.size( );
41 }
42
44 template<typename T, typename = void>
45 inline constexpr bool has_capacity_reserve_v = false;
46
47 template<typename T>
48 inline constexpr bool has_capacity_reserve_v<
49 T, std::void_t<decltype( std::declval<T &>( ).capacity( ) ),
50 decltype( std::declval<T &>( ).reserve(
51 std::size_t{ } ) )>> = true;
52
53 template<typename T>
54 DAW_CPP20_CONCEPT is_byte_type_v =
55 std::is_same_v<T, std::byte> or std::is_same_v<T, unsigned char>;
56
57 template<typename T>
58 DAW_CPP20_CONCEPT is_char_sized_character_v =
59 std::is_same_v<T, char>
60#if defined( __cpp_lib_char8_t )
61#if __cpp_lib_char8_t >= 201907L
62 or std::is_same_v<T, char8_t>
63#endif
64#endif
65 ;
66
67 template<typename T, typename CharT>
68 using span_like_range_test =
69 decltype( (void)( std::declval<T &>( ).subspan( 1 ) ),
70 (void)( std::declval<std::size_t &>( ) =
71 std::declval<T &>( ).size( ) ),
72 (void)( std::declval<bool &>( ) =
73 std::declval<T &>( ).empty( ) ),
74 (void)( *std::declval<T &>( ).data( ) =
75 std::declval<CharT>( ) ) );
76 // std::span has only subspan; daw::span and string views also have
77 // remove_prefix
78 template<typename T>
79 using remove_prefix_test =
80 decltype( std::declval<T &>( ).remove_prefix( std::size_t{ 1 } ) );
81
82 template<typename T>
83 DAW_CPP20_CONCEPT has_remove_prefix_v =
84 daw::is_detected_v<remove_prefix_test, T>;
85
86 template<typename T, typename CharT>
87 DAW_CPP20_CONCEPT is_span_like_range_v =
88 daw::is_detected_v<span_like_range_test, T, CharT> and
89 ( writeable_output_details::is_char_sized_character_v<CharT> or
90 writeable_output_details::is_byte_type_v<CharT> );
91
92 template<typename T, typename CharT>
93 using resizable_contiguous_range_test =
94 decltype( (void)( std::declval<T &>( ).resize( std::size_t{ 0 } ) ),
95 (void)( std::declval<T &>( ).size( ) ),
96 (void)( *std::declval<T &>( ).data( ) ),
97 (void)( *std::declval<T &>( ).data( ) =
98 std::declval<CharT>( ) ),
99 (void)( std::declval<T &>( ).push_back(
100 std::declval<CharT>( ) ) ),
101 (void)( static_cast<CharT>( 'a' ) ) );
102
103 template<typename Container, typename CharT>
104 DAW_CPP20_CONCEPT is_resizable_contiguous_range_v =
105 daw::is_detected_v<resizable_contiguous_range_test, Container, CharT>;
106
107 template<typename Container, typename CharT>
108 DAW_CPP20_CONCEPT is_string_like_writable_output_v =
109 ( writeable_output_details::is_char_sized_character_v<CharT> or
110 writeable_output_details::is_byte_type_v<CharT> ) and
111 writeable_output_details::is_resizable_contiguous_range_v<Container,
112 CharT>;
113
114 template<typename T>
115 using is_writable_output_iterator_test =
116 decltype( *std::declval<T &>( ) = 'c', ++std::declval<T &>( ) );
117
118 template<typename T>
119 DAW_CPP20_CONCEPT is_writable_output_iterator_v =
120 not std::is_pointer_v<T> and
121 daw::is_detected_v<is_writable_output_iterator_test, T>;
122 } // namespace concepts::writeable_output_details
123 } // namespace DAW_JSON_VER
124} // namespace daw::json
#define DAW_JSON_CPP23_STATIC_CALL_OP
string_writer grows its string with resize_and_overwrite, leaving the new bytes uninitialized,...
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20