[CXX-617] bsoncxx::builder::core::append of unsigned int? Created: 28/Jun/15  Updated: 11/Sep/19  Resolved: 28/Jun/15

Status: Closed
Project: C++ Driver
Component/s: BSON
Affects Version/s: 0.2.0
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: hczhcz Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux Mint 17.2 RC amd64
clang++ -std=c+11 -stdlib=libstdc+



 Description   

There are overloading versions of bsoncxx::builder::core::append that accepts native int32_t and int64_t.
But, calling it with a native uint is an error ("call to member function 'append' is ambiguous").

Example:
auto document = bsoncxx::builder::basic::document{};
document.append(kvp("foo", 42)); // ok
document.append(kvp("foo", 42u)); // error

Although we could use BSON value classes instead of native types, it needs more code if the type of value is a template argument.

template <class T>
void f(T value) {
document.append(kvp("foo", value));
}
f(42u); // error

Are there workarounds?
If not, should we edit the C++ driver and add these overloading functions?



 Comments   
Comment by hczhcz [ 29/Jun/15 ]

adam.midvidy, thanks!

Comment by Adam Midvidy [ 28/Jun/15 ]

hczhcz, this is actually by design. If you look at the BSON specification (http://bsonspec.org/spec.html) the two integer types supported are a 32-bit signed integer and a 64-bit signed integer.

It would be unsafe for us to provide an overload for unsigned integers as there would be the potential for overflow. I recommend instead that you static_cast your integral values to signed types before appending them to a document, if you can be sure that the values fit in the corresponding signed type.

Generated at Wed Feb 07 21:59:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.