DAW JSON Link
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 
11 #include "daw/json/impl/version.h"
12 
13 #include <daw/daw_is_detected.h>
14 
15 #include <cstddef>
16 #include <type_traits>
17 
18 namespace daw::json {
19  inline namespace DAW_JSON_VER {
20  namespace concepts {
21  namespace nullable_impl {
22 #if not defined( DAW_HAS_GCC ) or DAW_HAS_GCC_VER_GTE( 12, 0 )
23  template<typename T, typename... Args>
24  using is_list_constructible_test =
25  decltype( T{ std::declval<Args>( )... } );
26 #else
27  template<typename T, typename... Args>
28  using is_list_constructible_test =
29  decltype( std::declval<void ( * )( T )>( )(
30  { std::declval<Args>( )... } ) );
31 #endif
32  template<typename T, typename... Args>
33  inline constexpr bool is_list_constructible_v =
34  daw::is_detected_v<is_list_constructible_test, T, Args...>;
35 
36  template<typename T, typename... Args>
37  inline constexpr bool is_nullable_value_type_constructible_v =
38  std::is_constructible_v<T, Args...> or
39  is_list_constructible_v<T, Args...>;
40 
41  } // namespace nullable_impl
42 
44  explicit construct_nullable_with_value_t( ) = default;
45  };
46  inline constexpr auto construct_nullable_with_value =
48 
50  explicit construct_nullable_with_pointer_t( ) = default;
51  };
52  inline constexpr auto construct_nullable_with_pointer =
54 
56  explicit construct_nullable_with_empty_t( ) = default;
57  };
58  inline constexpr auto construct_nullable_with_empty =
60 
64  template<typename T, typename...>
66 
68  using value_type = T;
69 
71  using nullable_type = T;
72 
74  static constexpr bool is_nullable = false;
75 
79  inline constexpr value_type read( T const &v ) const noexcept {
80  return v;
81  }
83  DAW_JSON_CPP23_STATIC_CALL_OP inline constexpr nullable_type
86  noexcept( std::is_nothrow_default_constructible_v<value_type> ) {
87  return value_type{ };
88  }
90  template<typename... Args DAW_JSON_ENABLEIF(
91  nullable_impl::is_nullable_value_type_constructible_v<nullable_type,
92  Args...> )>
94  nullable_impl::is_nullable_value_type_constructible_v<nullable_type,
95  Args...> )
99  noexcept( std::is_nothrow_constructible_v<nullable_type, Args...> ) {
100  if constexpr( std::is_constructible_v<nullable_type, Args...> ) {
101  return T( DAW_FWD( args )... );
102  } else {
103  return T{ DAW_FWD( args )... };
104  }
105  }
107  static constexpr bool has_value( T const & ) noexcept {
108  return true;
109  }
110  };
112 
114  template<typename T>
117 
119  template<typename T>
120  inline constexpr bool is_nullable_value_v =
122 
124  template<typename T>
125  constexpr bool nullable_value_has_value( T const &opt ) {
127  }
128 
131  template<typename T>
132  constexpr auto const &nullable_value_read( T const &opt ) {
133  return nullable_value_traits<T>::read( opt );
134  }
135 
136  template<typename T, typename... Args>
137  inline constexpr bool is_nullable_value_constructible_v =
138  is_nullable_value_v<T> and
139  std::is_invocable_v<nullable_value_traits<T>,
141 
142  template<typename T, typename... Args>
143  inline constexpr bool is_nullable_pointer_constructible_v =
144  is_nullable_value_v<T> and
145  std::is_invocable_v<nullable_value_traits<T>,
147 
148  template<typename T, typename... Args>
150  is_nullable_value_constructible_v<T, Args...> and
151  std::is_nothrow_invocable_v<nullable_value_traits<T>,
153 
154  template<typename T>
155  inline constexpr bool is_nullable_empty_constructible_v =
156  is_nullable_value_v<T> and
157  std::is_invocable_v<nullable_value_traits<T>,
159 
160  template<typename T>
162  is_nullable_empty_constructible_v<T> and
163  std::is_nothrow_invocable_v<nullable_value_traits<T>,
165  } // namespace concepts
166  } // namespace DAW_JSON_VER
167 } // namespace daw::json
#define DAW_JSON_CPP23_STATIC_CALL_OP_DISABLE_WARNING
#define DAW_JSON_CPP23_STATIC_CALL_OP_CONST
#define DAW_JSON_ENABLEIF(...)
#define DAW_JSON_CPP23_STATIC_CALL_OP_ENABLE_WARNING
#define DAW_JSON_CPP23_STATIC_CALL_OP
This is in addition to the parse policy. Always do a full name match instead of sometimes relying on ...
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.
DAW_JSON_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:25