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 <cstdio>
20
21namespace daw::json {
22 inline namespace DAW_JSON_VER {
23 namespace concepts::writeable_output_details {
24 template<typename T>
25 constexpr T *copy_to_buffer( T *buff, daw::string_view source ) {
26#if defined( DAW_IS_CONSTANT_EVALUATED )
27 if( DAW_IS_CONSTANT_EVALUATED( ) ) {
28#endif
29 daw::algorithm::transform_n( source.data( ), buff, source.size( ),
30 []( auto c )
32 return static_cast<T>( c );
33 } );
34#if defined( DAW_IS_CONSTANT_EVALUATED )
35 } else {
36 memcpy( buff, source.data( ), source.size( ) );
37 }
38#endif
39 return buff + source.size( );
40 }
41
42 template<typename T>
43 inline constexpr bool is_byte_type_v =
44 std::is_same_v<T, std::byte> or std::is_same_v<T, unsigned char>;
45
46 template<typename T>
47 inline constexpr bool is_char_sized_character_v = false;
48
49 template<>
50 inline constexpr bool is_char_sized_character_v<char> = true;
51
52#if defined( __cpp_lib_char8_t )
53#if __cpp_lib_char8_t >= 201907L
54 template<>
55 inline constexpr bool is_char_sized_character_v<char8_t> = true;
56#endif
57#endif
58
59 template<typename T, typename CharT>
60 using span_like_range_test =
61 decltype( (void)( std::declval<T &>( ).subspan( 1 ) ),
62 (void)( std::declval<std::size_t &>( ) =
63 std::declval<T &>( ).size( ) ),
64 (void)( std::declval<bool &>( ) =
65 std::declval<T &>( ).empty( ) ),
66 (void)( *std::declval<T &>( ).data( ) =
67 std::declval<CharT>( ) ) );
68 template<typename T, typename CharT>
69 inline constexpr bool is_span_like_range_v =
70 daw::is_detected_v<span_like_range_test, T, CharT> and
71 ( writeable_output_details::is_char_sized_character_v<CharT> or
72 writeable_output_details::is_byte_type_v<CharT> );
73
74 template<typename T, typename CharT>
75 using resizable_contiguous_range_test =
76 decltype( (void)( std::declval<T &>( ).resize( std::size_t{ 0 } ) ),
77 (void)( std::declval<T &>( ).size( ) ),
78 (void)( *std::declval<T &>( ).data( ) ),
79 (void)( *std::declval<T &>( ).data( ) =
80 std::declval<CharT>( ) ),
81 (void)( std::declval<T &>( ).push_back(
82 std::declval<CharT>( ) ) ),
83 (void)( static_cast<CharT>( 'a' ) ) );
84
85 template<typename Container, typename CharT>
86 inline constexpr bool is_resizable_contiguous_range_v =
87 daw::is_detected_v<resizable_contiguous_range_test, Container, CharT>;
88
89 template<typename Container, typename CharT>
90 inline constexpr bool is_string_like_writable_output_v =
91 (writeable_output_details::is_char_sized_character_v<CharT> or
92 writeable_output_details::is_byte_type_v<
93 CharT>)and writeable_output_details::
94 is_resizable_contiguous_range_v<Container, CharT>;
95
96 template<typename T>
97 using is_writable_output_iterator_test =
98 decltype( *std::declval<T &>( ) = 'c', ++std::declval<T &>( ) );
99
100 template<typename T>
101 inline constexpr bool is_writable_output_iterator_v =
102 not std::is_pointer_v<T> and
103 daw::is_detected_v<is_writable_output_iterator_test, T>;
104 } // namespace concepts::writeable_output_details
105 } // namespace DAW_JSON_VER
106} // namespace daw::json
#define DAW_JSON_CPP23_STATIC_CALL_OP
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20