@@ -85,12 +85,12 @@ struct simdjson_result : public std::pair<T, error_code> {
8585 /* *
8686 * Move the value and the error to the provided variables.
8787 */
88- void tie (T& t, error_code & e) {
88+ void tie (T& t, error_code & e) && noexcept {
8989 // on the clang compiler that comes with current macOS (Apple clang version 11.0.0),
9090 // tie(width, error) = size["w"].as_uint64_t();
9191 // 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 ;
9494 }
9595
9696 /* *
@@ -105,106 +105,51 @@ struct simdjson_result : public std::pair<T, error_code> {
105105 *
106106 * @throw simdjson_error if there was an error.
107107 */
108- T get () noexcept (false ) {
108+ T& get () noexcept (false ) {
109109 if (error ()) { throw simdjson_error (error ()); }
110110 return this ->first ;
111111 };
112112
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-
170113 /* *
171114 * The value of the function.
172115 *
173116 * @throw simdjson_error if there was an error.
174117 */
175- T move () noexcept ( false ) {
118+ T&& take () && {
176119 if (error ()) { throw simdjson_error (error ()); }
177- return std::move (this ->first );
120+ return std::forward<T> (this ->first );
178121 };
179122
180123 /* *
181124 * Cast to the value (will throw on error).
182125 *
183126 * @throw simdjson_error if there was an error.
184127 */
185- operator T () noexcept (false ) { return move (); }
128+ operator T&&() && {
129+ return std::forward<simdjson_result<T>>(*this ).take ();
130+ }
186131
187- #endif
132+ #endif // SIMDJSON_EXCEPTIONS
188133
189134 /* *
190135 * Create a new empty result with error = UNINITIALIZED.
191136 */
192- simdjson_move_result () noexcept : simdjson_move_result (UNINITIALIZED ) {}
137+ simdjson_result () noexcept : simdjson_result (UNINITIALIZED ) {}
193138
194139 /* *
195140 * Create a new error result.
196141 */
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) {}
198143
199144 /* *
200145 * Create a new successful result.
201146 */
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 ) {}
203148
204149 /* *
205150 * Create a new result with both things (use if you don't want to branch when creating the result).
206151 */
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) {}
208153};
209154
210155/* *
0 commit comments