[CXX-937] How to stream a std::size_t variable into bsoncxx::builder::stream::document Created: 17/Jun/16  Updated: 11/Sep/19  Resolved: 18/Jun/16

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: 3.0.1
Fix Version/s: None

Type: Task Priority: Trivial - P5
Reporter: George Thompson Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10
MS VS 2015
MongoDB 3.3.5
MongoDB C++11 Driver 3.0.1



 Description   

Class variable:

std::size_t key_;

Note: My class design is designed to be able to operate with any DB, not just MongoDB.

Code:

bsoncxx::builder::stream::document bsb_field_design;
bsb_field_design << "t4id"   << field_design.id_
                 << "t4name" << field_design.name_
                 << "t4type" << field_design.type_
                 << "t4key"  << field_design.key_
...

Gives a lengthy error (appended below) that (I believe) is saying it can't figure out how to handle size_t from the last line of the code.

My (unsatisfying) solution:

       << "t4key" << static_cast<int>(field_design.key_)

Is that my only solution?

Error message:

1>C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/stream/value_context.hpp(70): error C2668: 'bsoncxx::v_noabi::builder::core::append': ambiguous call to overloaded function
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(263): note: could be 'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::oid &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(258): note: or       'void bsoncxx::v_noabi::builder::core::append(int64_t)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(253): note: or       'void bsoncxx::v_noabi::builder::core::append(int32_t)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(248): note: or       'void bsoncxx::v_noabi::builder::core::append(double)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(243): note: or       'void bsoncxx::v_noabi::builder::core::append(bool)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(225): note: or       'void bsoncxx::v_noabi::builder::core::append(bsoncxx::stdx::string_view)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(220): note: or       'void bsoncxx::v_noabi::builder::core::append(std::string)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(215): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::value &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(210): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_maxkey &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(205): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_minkey &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(200): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_int64 &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(195): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_timestamp &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(190): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_int32 &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(185): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_codewscope &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(180): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_symbol &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(175): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_code &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(170): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_dbpointer &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(165): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_regex &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(160): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_null &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(155): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_date &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(150): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_bool &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(145): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_oid &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(140): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_undefined &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(135): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_binary &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(130): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_array &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(125): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_document &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(120): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_utf8 &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/core.hpp(115): note: or       'void bsoncxx::v_noabi::builder::core::append(const bsoncxx::v_noabi::types::b_double &)'
1>  C:\build\install\include\bsoncxx\v_noabi\bsoncxx/builder/stream/value_context.hpp(70): note: while trying to match the argument list '(size_t)'
1>  ..\..\..\..\..\..\..\T4 2.0\src\mongoDB\src\T4DBFileBlueprintFunctions.cpp(245): note: see reference to function template instantiation 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context> bsoncxx::v_noabi::builder::stream::value_context<bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>>::operator <<<size_t&>(T)' being compiled
1>          with
1>          [
1>              T=size_t &
1>          ]



 Comments   
Comment by George Thompson [ 17/Jun/16 ]

Thank you Andrew. I will work around this.

Comment by Andrew Morrow (Inactive) [ 17/Jun/16 ]

Hi therefore -

The issue is that the BSON specification only supports 32 and 64 bit signed integral types (http://bsonspec.org/spec.html). As such, the bsoncxx::builder::core type only accepts std::int32_t and std::int64_t directly. Adding other overloads, like one accepting an unsigned type like size_t, would be problematic, as we cannot with full fidelity encode all values of that type.

Potentially, for a 32-bit size_t, we could promote into signed 64-bit, but that would also be a risky choice.

If you need to encode the full range of 64-bit unsigned values, you can do so via casting, but the application must be aware of the semantics and deal with casting on both sides.

Generated at Wed Feb 07 22:00:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.