@@ -85,12 +85,12 @@ struct simdjson_result : public std::pair<T, error_code> {
85
85
/* *
86
86
* Move the value and the error to the provided variables.
87
87
*/
88
- void tie (T& t, error_code & e) {
88
+ void tie (T& t, error_code & e) && noexcept {
89
89
// on the clang compiler that comes with current macOS (Apple clang version 11.0.0),
90
90
// tie(width, error) = size["w"].as_uint64_t();
91
91
// fails with "error: no viable overloaded '='""
92
- t = std::move ( this -> first ) ;
93
- e = std::move ( this ->second ) ;
92
+ t = std::forward<simdjson_result<T>>(* this ). first ;
93
+ e = this ->second ;
94
94
}
95
95
96
96
/* *
@@ -105,106 +105,51 @@ struct simdjson_result : public std::pair<T, error_code> {
105
105
*
106
106
* @throw simdjson_error if there was an error.
107
107
*/
108
- T get () noexcept (false ) {
108
+ T& get () noexcept (false ) {
109
109
if (error ()) { throw simdjson_error (error ()); }
110
110
return this ->first ;
111
111
};
112
112
113
- /* *
114
- * Cast to the value (will throw on error).
115
- *
116
- * @throw simdjson_error if there was an error.
117
- */
118
- operator T () noexcept (false ) { return get (); }
119
-
120
- #endif // SIMDJSON_EXCEPTIONS
121
-
122
- /* *
123
- * Create a new empty result with error = UNINITIALIZED.
124
- */
125
- simdjson_result () noexcept : simdjson_result(UNINITIALIZED) {}
126
-
127
- /* *
128
- * Create a new error result.
129
- */
130
- simdjson_result (error_code _error) noexcept : std::pair<T, error_code>({}, _error) {}
131
-
132
- /* *
133
- * Create a new successful result.
134
- */
135
- simdjson_result (T _value) noexcept : std::pair<T, error_code>(_value, SUCCESS) {}
136
-
137
- /* *
138
- * Create a new result with both things (use if you don't want to branch when creating the result).
139
- */
140
- simdjson_result (T value, error_code error) noexcept : std::pair<T, error_code>(value, error) {}
141
- };
142
-
143
- /* *
144
- * The result of a simd operation that could fail.
145
- *
146
- * This class is for values that must be *moved*, like padded_string and document.
147
- *
148
- * Gives the option of reading error codes, or throwing an exception by casting to the desired result.
149
- */
150
- template <typename T>
151
- struct simdjson_move_result : std::pair<T, error_code> {
152
- /* *
153
- * Move the value and the error to the provided variables.
154
- */
155
- void tie (T& t, error_code & e) {
156
- // on the clang compiler that comes with current macOS (Apple clang version 11.0.0),
157
- // std::tie(this->json, error) = padded_string::load(filename);
158
- // fails with "benchmark/benchmarker.h:266:33: error: no viable overloaded '='""
159
- t = std::move (this ->first );
160
- e = std::move (this ->second );
161
- }
162
-
163
- /* *
164
- * The error.
165
- */
166
- error_code error () const { return this ->second ; }
167
-
168
- #if SIMDJSON_EXCEPTIONS
169
-
170
113
/* *
171
114
* The value of the function.
172
115
*
173
116
* @throw simdjson_error if there was an error.
174
117
*/
175
- T move () noexcept ( false ) {
118
+ T&& take () && {
176
119
if (error ()) { throw simdjson_error (error ()); }
177
- return std::move (this ->first );
120
+ return std::forward<T> (this ->first );
178
121
};
179
122
180
123
/* *
181
124
* Cast to the value (will throw on error).
182
125
*
183
126
* @throw simdjson_error if there was an error.
184
127
*/
185
- operator T () noexcept (false ) { return move (); }
128
+ operator T&&() && {
129
+ return std::forward<simdjson_result<T>>(*this ).take ();
130
+ }
186
131
187
- #endif
132
+ #endif // SIMDJSON_EXCEPTIONS
188
133
189
134
/* *
190
135
* Create a new empty result with error = UNINITIALIZED.
191
136
*/
192
- simdjson_move_result () noexcept : simdjson_move_result (UNINITIALIZED) {}
137
+ simdjson_result () noexcept : simdjson_result (UNINITIALIZED) {}
193
138
194
139
/* *
195
140
* Create a new error result.
196
141
*/
197
- simdjson_move_result (error_code error) noexcept : std::pair<T, error_code>(T() , error) {}
142
+ simdjson_result (error_code error) noexcept : std::pair<T, error_code>(T{} , error) {}
198
143
199
144
/* *
200
145
* Create a new successful result.
201
146
*/
202
- simdjson_move_result (T value) noexcept : std::pair<T, error_code>(std::move (value), SUCCESS) {}
147
+ simdjson_result (T && value) noexcept : std::pair<T, error_code>(std::forward<T> (value), SUCCESS) {}
203
148
204
149
/* *
205
150
* Create a new result with both things (use if you don't want to branch when creating the result).
206
151
*/
207
- simdjson_move_result (T value, error_code error) noexcept : std::pair<T, error_code>(std::move (value), error) {}
152
+ simdjson_result (T && value, error_code error) noexcept : std::pair<T, error_code>(std::forward<T> (value), error) {}
208
153
};
209
154
210
155
/* *
0 commit comments