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> |
24 | simdjson_inline error_code implementation_simdjson_result_base<T>::error() const noexcept { |
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> |
70 | simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(T &&value, error_code error) noexcept |
71 | : first{std::forward<T>(value)}, second{error} {} |
72 | template<typename T> |
73 | simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(error_code error) noexcept |
74 | : implementation_simdjson_result_base(T{}, error) {} |
75 | template<typename T> |
76 | simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(T &&value) noexcept |
77 | : implementation_simdjson_result_base(std::forward<T>(value), SUCCESS) {} |
78 | |
79 | } // namespace SIMDJSON_IMPLEMENTATION |
80 | } // namespace simdjson |
81 |