DAW JSON Link
Loading...
Searching...
No Matches
daw_nullable_value_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_callable.h"
14
15#include <daw/daw_cpp_feature_check.h>
16#include <daw/daw_enable_requires.h>
17#include <daw/daw_is_detected.h>
18
19#include <cstddef>
20#include <type_traits>
21
22namespace daw::json {
23 inline namespace DAW_JSON_VER {
24 namespace concepts {
25 namespace nullable_impl {
26#if not defined( DAW_HAS_GCC ) or DAW_HAS_GCC_VER_GTE( 12, 0 )
27 template<typename T, typename... Args>
28 using is_list_constructible_test =
29 decltype( T{ std::declval<Args>( )... } );
30#else
31 template<typename T, typename... Args>
32 using is_list_constructible_test =
33 decltype( std::declval<void ( * )( T )>( )(
34 { std::declval<Args>( )... } ) );
35#endif
36 template<typename T, typename... Args>
37 DAW_CPP20_CONCEPT is_list_constructible_v =
38 daw::is_detected_v<is_list_constructible_test, T, Args...>;
39
40 template<typename T, typename... Args>
41 DAW_CPP20_CONCEPT is_nullable_value_type_constructible_v =
42 std::is_constructible_v<T, Args...> or
43 is_list_constructible_v<T, Args...>;
44 } // namespace nullable_impl
45
51
57
63
67 template<typename T, typename...>
69
71 using value_type = T;
72
74 using nullable_type = T;
75
77 static constexpr bool is_nullable = false;
78
82 constexpr value_type read( T const &v ) const noexcept {
83 return v;
84 }
88 noexcept( std::is_nothrow_default_constructible_v<value_type> ) {
89 return value_type{ };
90 }
92 template<typename... Args DAW_ENABLEIF(
93 nullable_impl::is_nullable_value_type_constructible_v<nullable_type,
94 Args...> )>
95 DAW_REQUIRES( nullable_impl::is_nullable_value_type_constructible_v<
96 nullable_type, Args...> )
100 noexcept( std::is_nothrow_constructible_v<nullable_type, Args...> ) {
101 if constexpr( std::is_constructible_v<nullable_type, Args...> ) {
102 return T( DAW_FWD( args )... );
103 } else {
104 return T{ DAW_FWD( args )... };
105 }
106 }
108 static constexpr bool has_value( T const & ) noexcept {
109 return true;
110 }
111 };
113
115 template<typename T>
118
120 template<typename T>
121 DAW_CPP20_CONCEPT is_nullable_value_v =
123
125 template<typename T>
126 constexpr bool nullable_value_has_value( T const &opt ) {
128 }
129
132 template<typename T>
133 constexpr auto const &nullable_value_read( T const &opt ) {
134 return nullable_value_traits<T>::read( opt );
135 }
136
137 template<typename T, typename... Args>
139 is_nullable_value_v<T> and
140 daw::is_callable_v<nullable_value_traits<T>,
142
143 template<typename T, typename... Args>
145 is_nullable_value_v<T> and
146 daw::is_callable_v<nullable_value_traits<T>,
148
149 template<typename T, typename... Args>
152 daw::is_nothrow_callable_v<nullable_value_traits<T>,
154
155 template<typename T>
157 is_nullable_value_v<T> and
158 daw::is_callable_v<nullable_value_traits<T>,
160
161 template<typename T>
163 is_nullable_empty_constructible_v<T> and
164 daw::is_nothrow_callable_v<nullable_value_traits<T>,
166
167 } // namespace concepts
168 } // namespace DAW_JSON_VER
169} // namespace daw::json
#define DAW_JSON_CPP23_STATIC_CALL_OP_DISABLE_WARNING
#define DAW_JSON_CPP23_STATIC_CALL_OP_CONST
#define DAW_JSON_CPP23_STATIC_CALL_OP_ENABLE_WARNING
#define DAW_JSON_CPP23_STATIC_CALL_OP
constexpr bool nullable_value_has_value(T const &opt)
Check if nullable value has a value.
constexpr auto const & nullable_value_read(T const &opt)
Read value from a non-empty nullable value.
typename nullable_value_traits< T >::value_type nullable_value_type_t
Determines the type stored inside T.
Customization point traits.
static constexpr bool has_value(T const &) noexcept
Check the state of the nullable type for a value.
constexpr value_type read(T const &v) const noexcept
read the value in the nullable type
DAW_REQUIRES(nullable_impl::is_nullable_value_type_constructible_v< nullable_type, Args... >) DAW_JSON_CPP23_STATIC_CALL_OP const expr nullable_type operator()(const ruct_nullable_with_empty_t
Return an empty nullable type.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20