diff options
author | Mathias Stearn <mathias@10gen.com> | 2016-06-02 17:55:48 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2016-06-09 13:00:49 -0400 |
commit | b354fbae71aea007759e174c31a869f55fe6502f (patch) | |
tree | 4dad411c68a1b6dd9184438e7777140519d6c65a /src/mongo/bson/bsonobjbuilder.h | |
parent | 6335744b8af97e4f5b3fb15118f24833df6e7047 (diff) | |
download | mongo-b354fbae71aea007759e174c31a869f55fe6502f.tar.gz |
SERVER-4536 Support appending an int64_t to a BSONObjBuilder
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder.h')
-rw-r--r-- | src/mongo/bson/bsonobjbuilder.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h index 3a3f91a60cf..74593287942 100644 --- a/src/mongo/bson/bsonobjbuilder.h +++ b/src/mongo/bson/bsonobjbuilder.h @@ -35,6 +35,7 @@ #pragma once #include <cmath> +#include <cstdint> #include <limits> #include <map> @@ -45,6 +46,7 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobj.h" #include "mongo/platform/decimal128.h" +#include "mongo/stdx/type_traits.h" #include "mongo/util/itoa.h" namespace mongo { @@ -270,6 +272,19 @@ public: return *this; } + /** + * Append a NumberLong (if int64_t isn't the same as long long) + */ + template <typename Int64_t, + typename = stdx::enable_if_t<std::is_same<Int64_t, int64_t>::value && + !std::is_same<int64_t, long long>::value>> + BSONObjBuilder& append(StringData fieldName, Int64_t n) { + _b.appendNum((char)NumberLong); + _b.appendStr(fieldName); + _b.appendNum(n); + return *this; + } + /** appends a number. if n < max(int)/2 then uses int, otherwise long long */ BSONObjBuilder& appendIntOrLL(StringData fieldName, long long n) { // extra () to avoid max macro on windows |