Skip to content

Commit 6df158d

Browse files
silvakidrsomla1
authored andcommitted
Fix Value() conversion int/long/signed/unsigned
1 parent 2d764a8 commit 6df158d

File tree

1 file changed

+82
-10
lines changed

1 file changed

+82
-10
lines changed

include/devapi/document.h

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,6 @@ class PUBLIC_API Value : public internal::Printable
285285
Value(bool);
286286
Value(const DbDoc& doc);
287287

288-
/*
289-
Note: These overloads are needed to disambiguate constructor
290-
resolution.
291-
*/
292-
293-
Value(int x) : Value((int64_t)x) {}
294-
Value(unsigned x) : Value((uint64_t)x) {}
295-
Value(long x) : Value((int64_t)x) {}
296-
Value(unsigned long x) : Value((uint64_t)x) {}
297-
298288
Value(const std::initializer_list<Value> &list)
299289
: m_type(ARRAY)
300290
{
@@ -310,6 +300,65 @@ class PUBLIC_API Value : public internal::Printable
310300

311301
///@}
312302

303+
/*
304+
Note: These templates are needed to disambiguate constructor resolution
305+
for integer types.
306+
*/
307+
308+
Value(const Value&) = default;
309+
310+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
311+
312+
Value(Value&&) = default;
313+
314+
#else
315+
316+
Value(Value &&other)
317+
{
318+
*this = std::move(other);
319+
}
320+
321+
#endif
322+
323+
template <
324+
typename T,
325+
typename std::enable_if<std::is_signed<T>::value>::type* = nullptr
326+
>
327+
Value(T x)
328+
: Value(static_cast<int64_t>(x))
329+
{}
330+
331+
template <
332+
typename T,
333+
typename std::enable_if<std::is_unsigned<T>::value>::type* = nullptr
334+
>
335+
Value(T x)
336+
: Value(static_cast<uint64_t>(x))
337+
{}
338+
339+
/*
340+
Assignment operator is implemented using constructors.
341+
*/
342+
343+
Value& operator=(const Value&) = default;
344+
345+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
346+
347+
Value& operator=(Value&&) = default;
348+
349+
#else
350+
351+
Value& operator=(Value&&);
352+
353+
#endif
354+
355+
template<typename T>
356+
Value& operator=(T x)
357+
{
358+
*this = Value(x);
359+
return *this;
360+
}
361+
313362
private:
314363

315364
/*
@@ -461,6 +510,29 @@ class PUBLIC_API Value : public internal::Printable
461510
static const Value nullvalue;
462511

463512

513+
#if defined(_MSC_VER) && _MSC_VER < 1900
514+
515+
inline
516+
Value& Value::operator=(Value &&other)
517+
{
518+
m_type = other.m_type;
519+
m_val = other.m_val;
520+
521+
switch (m_type)
522+
{
523+
case STRING: m_str = std::move(other.m_str); break;
524+
case DOCUMENT: m_doc = std::move(other.m_doc); break;
525+
case RAW: m_raw = std::move(other.m_raw); break;
526+
case ARRAY: m_arr = std::move(other.m_arr); break;
527+
default: break;
528+
}
529+
530+
return *this;
531+
}
532+
533+
#endif
534+
535+
464536
namespace internal {
465537

466538
/*

0 commit comments

Comments
 (0)