Skip to content

Commit 0750522

Browse files
committed
try_decode_json
1 parent 5343872 commit 0750522

File tree

2 files changed

+5
-51
lines changed

2 files changed

+5
-51
lines changed

include/jsoncons/reflect/conv_result.hpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,6 @@ class conv_result
136136
JSONCONS_THROW(std::runtime_error("Bad conv_result access"));
137137
}
138138

139-
constexpr T value_or(T&& default_value) const &
140-
{
141-
static_assert(std::is_copy_constructible<T>::value,
142-
"get_value_or: T must be copy constructible");
143-
static_assert(std::is_convertible<T&&, T>::value,
144-
"get_value_or: T must be convertible to T");
145-
return static_cast<bool>(*this)
146-
? **this
147-
: static_cast<T>(std::forward<T>(default_value));
148-
}
149-
150-
T value_or(T&& default_value) &&
151-
{
152-
static_assert(std::is_move_constructible<T>::value,
153-
"get_value_or: T must be move constructible");
154-
static_assert(std::is_convertible<T&&, T>::value,
155-
"get_value_or: T must be convertible to T");
156-
return static_cast<bool>(*this) ? std::move(**this)
157-
: static_cast<T>(std::forward<T>(default_value));
158-
}
159-
160139
constexpr const T* operator->() const
161140
{
162141
return std::addressof(this->value_);
@@ -222,16 +201,15 @@ class conv_result
222201
}
223202
}
224203

225-
template <typename T>
226204
void assign(T&& u)
227205
{
228206
if (has_value_)
229207
{
230-
value_ = std::forward<T>(u);
208+
value_ = std::move(u);
231209
}
232210
else
233211
{
234-
construct(std::forward<T>(u));
212+
construct(std::move(u));
235213
}
236214
}
237215
};

include/jsoncons/reflect/decode_result.hpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,6 @@ class decode_result
176176
JSONCONS_THROW(std::runtime_error("Bad decode_result access"));
177177
}
178178

179-
template <typename U>
180-
constexpr T value_or(U&& default_value) const &
181-
{
182-
static_assert(std::is_copy_constructible<T>::value,
183-
"get_value_or: T must be copy constructible");
184-
static_assert(std::is_convertible<U&&, T>::value,
185-
"get_value_or: U must be convertible to T");
186-
return static_cast<bool>(*this)
187-
? **this
188-
: static_cast<T>(std::forward<U>(default_value));
189-
}
190-
191-
template <typename U>
192-
T value_or(U&& default_value) &&
193-
{
194-
static_assert(std::is_move_constructible<T>::value,
195-
"get_value_or: T must be move constructible");
196-
static_assert(std::is_convertible<U&&, T>::value,
197-
"get_value_or: U must be convertible to T");
198-
return static_cast<bool>(*this) ? std::move(**this)
199-
: static_cast<T>(std::forward<U>(default_value));
200-
}
201-
202179
constexpr const T* operator->() const
203180
{
204181
return std::addressof(this->value_);
@@ -264,16 +241,15 @@ class decode_result
264241
}
265242
}
266243

267-
template <typename U>
268-
void assign(U&& u)
244+
void assign(T&& u)
269245
{
270246
if (has_value_)
271247
{
272-
value_ = std::forward<U>(u);
248+
value_ = std::move(u);
273249
}
274250
else
275251
{
276-
construct(std::forward<U>(u));
252+
construct(std::move(u));
277253
}
278254
}
279255
};

0 commit comments

Comments
 (0)