simdjson 4.2.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
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
9namespace simdjson {
10namespace SIMDJSON_IMPLEMENTATION {
11
12//
13// internal::implementation_simdjson_result_base<T> inline implementation
14//
15
16template<typename T>
17simdjson_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
24template<typename T>
25simdjson_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
31template<typename T>
32simdjson_warn_unused simdjson_inline error_code implementation_simdjson_result_base<T>::error() const noexcept {
33 return this->second;
34}
35
36
37template<typename T>
38simdjson_warn_unused simdjson_inline bool implementation_simdjson_result_base<T>::has_value() const noexcept {
39 return this->error() == SUCCESS;
40}
41
42#if SIMDJSON_EXCEPTIONS
43
44template<typename T>
45simdjson_inline T& implementation_simdjson_result_base<T>::operator*() & noexcept(false) {
46 return this->value();
47}
48
49template<typename T>
50simdjson_inline T&& implementation_simdjson_result_base<T>::operator*() && noexcept(false) {
51 return std::forward<implementation_simdjson_result_base<T>>(*this).value();
52}
53
54template<typename T>
55simdjson_inline T* implementation_simdjson_result_base<T>::operator->() noexcept(false) {
56 if (this->error()) { throw simdjson_error(this->error()); }
57 return &this->first;
58}
59
60
61template<typename T>
62simdjson_inline const T* implementation_simdjson_result_base<T>::operator->() const noexcept(false) {
63 if (this->error()) { throw simdjson_error(this->error()); }
64 return &this->first;
65}
66
67template<typename T>
68simdjson_inline T& implementation_simdjson_result_base<T>::value() & noexcept(false) {
69 if (error()) { throw simdjson_error(error()); }
70 return this->first;
71}
72
73template<typename T>
74simdjson_inline T&& implementation_simdjson_result_base<T>::value() && noexcept(false) {
75 return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
76}
77
78template<typename T>
79simdjson_inline T&& implementation_simdjson_result_base<T>::take_value() && noexcept(false) {
80 if (error()) { throw simdjson_error(error()); }
81 return std::forward<T>(this->first);
82}
83
84template<typename T>
85simdjson_inline implementation_simdjson_result_base<T>::operator T&&() && noexcept(false) {
86 return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
87}
88
89#endif // SIMDJSON_EXCEPTIONS
90
91template<typename T>
92simdjson_inline const T& implementation_simdjson_result_base<T>::value_unsafe() const& noexcept {
93 return this->first;
94}
95
96template<typename T>
98 return this->first;
99}
100
101template<typename T>
103 return std::forward<T>(this->first);
104}
105
106template<typename T>
108 : first{std::forward<T>(value)}, second{error} {}
109template<typename T>
112template<typename T>
115
116} // namespace SIMDJSON_IMPLEMENTATION
117} // namespace simdjson
118
119#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_warn_unused simdjson_inline bool has_value() const noexcept
Whether there is a value.
simdjson_inline const T & value_unsafe() const &noexcept
Get the result value.
simdjson_warn_unused 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 * operator->() noexcept(false)
Arrow operator to access members of the contained value.
simdjson_warn_unused simdjson_inline error_code error() const noexcept
The error.
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:91