simdjson  3.1.7
Ridiculously Fast JSON
implementation_simdjson_result_base-inl.h
1 namespace simdjson {
2 namespace SIMDJSON_IMPLEMENTATION {
3 
4 //
5 // internal::implementation_simdjson_result_base<T> inline implementation
6 //
7 
8 template<typename T>
9 simdjson_inline void implementation_simdjson_result_base<T>::tie(T &value, error_code &error) && noexcept {
10  error = this->second;
11  if (!error) {
12  value = std::forward<implementation_simdjson_result_base<T>>(*this).first;
13  }
14 }
15 
16 template<typename T>
17 simdjson_warn_unused simdjson_inline error_code implementation_simdjson_result_base<T>::get(T &value) && noexcept {
18  error_code error;
19  std::forward<implementation_simdjson_result_base<T>>(*this).tie(value, error);
20  return error;
21 }
22 
23 template<typename T>
25  return this->second;
26 }
27 
28 #if SIMDJSON_EXCEPTIONS
29 
30 template<typename T>
31 simdjson_inline T& implementation_simdjson_result_base<T>::value() & noexcept(false) {
32  if (error()) { throw simdjson_error(error()); }
33  return this->first;
34 }
35 
36 template<typename T>
37 simdjson_inline T&& implementation_simdjson_result_base<T>::value() && noexcept(false) {
38  return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
39 }
40 
41 template<typename T>
42 simdjson_inline T&& implementation_simdjson_result_base<T>::take_value() && noexcept(false) {
43  if (error()) { throw simdjson_error(error()); }
44  return std::forward<T>(this->first);
45 }
46 
47 template<typename T>
48 simdjson_inline implementation_simdjson_result_base<T>::operator T&&() && noexcept(false) {
49  return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
50 }
51 
52 #endif // SIMDJSON_EXCEPTIONS
53 
54 template<typename T>
55 simdjson_inline const T& implementation_simdjson_result_base<T>::value_unsafe() const& noexcept {
56  return this->first;
57 }
58 
59 template<typename T>
60 simdjson_inline T& implementation_simdjson_result_base<T>::value_unsafe() & noexcept {
61  return this->first;
62 }
63 
64 template<typename T>
65 simdjson_inline T&& implementation_simdjson_result_base<T>::value_unsafe() && noexcept {
66  return std::forward<T>(this->first);
67 }
68 
69 template<typename T>
71  : first{std::forward<T>(value)}, second{error} {}
72 template<typename T>
75 template<typename T>
77  : implementation_simdjson_result_base(std::forward<T>(value), SUCCESS) {}
78 
79 } // namespace SIMDJSON_IMPLEMENTATION
80 } // namespace simdjson
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
Definition: error.h:17
@ SUCCESS
No error.
Definition: error.h:18
simdjson_inline implementation_simdjson_result_base() noexcept=default
Create a new empty result with error = UNINITIALIZED.
simdjson_inline T & value() &noexcept(false)
Get the result value.
simdjson_inline const T & value_unsafe() const &noexcept
Get the result value.
simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
simdjson_inline void tie(T &value, error_code &error) &&noexcept
Move the value and the error to the provided variables.
simdjson_inline T && take_value() &&noexcept(false)
Take the result value (move it).
Exception thrown when an exception-supporting simdjson method is called.
Definition: error.h:72