simdjson  3.11.0
Ridiculously Fast JSON
implementation_simdjson_result_base-inl.h
1 #ifndef SIMDJSON_GENERIC_IMPLEMENTATION_SIMDJSON_RESULT_BASE_INL_H
2 
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_IMPLEMENTATION_SIMDJSON_RESULT_BASE_INL_H
5 #include "simdjson/generic/base.h"
6 #include "simdjson/generic/implementation_simdjson_result_base.h"
7 #endif // SIMDJSON_CONDITIONAL_INCLUDE
8 
9 namespace simdjson {
10 namespace SIMDJSON_IMPLEMENTATION {
11 
12 //
13 // internal::implementation_simdjson_result_base<T> inline implementation
14 //
15 
16 template<typename T>
17 simdjson_inline void implementation_simdjson_result_base<T>::tie(T &value, error_code &error) && noexcept {
18  error = this->second;
19  if (!error) {
20  value = std::forward<implementation_simdjson_result_base<T>>(*this).first;
21  }
22 }
23 
24 template<typename T>
25 simdjson_warn_unused simdjson_inline error_code implementation_simdjson_result_base<T>::get(T &value) && noexcept {
26  error_code error;
27  std::forward<implementation_simdjson_result_base<T>>(*this).tie(value, error);
28  return error;
29 }
30 
31 template<typename T>
33  return this->second;
34 }
35 
36 #if SIMDJSON_EXCEPTIONS
37 
38 template<typename T>
39 simdjson_inline T& implementation_simdjson_result_base<T>::value() & noexcept(false) {
40  if (error()) { throw simdjson_error(error()); }
41  return this->first;
42 }
43 
44 template<typename T>
45 simdjson_inline T&& implementation_simdjson_result_base<T>::value() && noexcept(false) {
46  return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
47 }
48 
49 template<typename T>
50 simdjson_inline T&& implementation_simdjson_result_base<T>::take_value() && noexcept(false) {
51  if (error()) { throw simdjson_error(error()); }
52  return std::forward<T>(this->first);
53 }
54 
55 template<typename T>
56 simdjson_inline implementation_simdjson_result_base<T>::operator T&&() && noexcept(false) {
57  return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
58 }
59 
60 #endif // SIMDJSON_EXCEPTIONS
61 
62 template<typename T>
63 simdjson_inline const T& implementation_simdjson_result_base<T>::value_unsafe() const& noexcept {
64  return this->first;
65 }
66 
67 template<typename T>
68 simdjson_inline T& implementation_simdjson_result_base<T>::value_unsafe() & noexcept {
69  return this->first;
70 }
71 
72 template<typename T>
73 simdjson_inline T&& implementation_simdjson_result_base<T>::value_unsafe() && noexcept {
74  return std::forward<T>(this->first);
75 }
76 
77 template<typename T>
79  : first{std::forward<T>(value)}, second{error} {}
80 template<typename T>
83 template<typename T>
85  : implementation_simdjson_result_base(std::forward<T>(value), SUCCESS) {}
86 
87 } // namespace SIMDJSON_IMPLEMENTATION
88 } // namespace simdjson
89 
90 #endif // SIMDJSON_GENERIC_IMPLEMENTATION_SIMDJSON_RESULT_BASE_INL_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
error_code
All possible errors returned by simdjson.
Definition: error.h:19
@ SUCCESS
No error.
Definition: error.h:20
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:82