c++bsonmongo-cxx-driver

Why am I getting an error when assigning a bsoncxx::document to another bsoncxx::document?


Using various options, I'm attempting to build a compound query using bsoncxx::builder::basic::document objects. So I can build

auto these_guys = bsoncxx::builder::basic::document{};
these_guys.append( kvp("Name", "Smith") );

and

auto those_guys = bsoncxx::builder::basic::document{};
those_guys.append( kvp("Name", "Jones") );

and then based on some parameters

auto full_query = bsoncxx::builder::basic::document{};
if (these && those)
{
    full_query.append(kvp("$and", make_array(these_guys , those_guys)));
}
else if (these)
{
    full_query = these_guys;   // <--- E1776 here
} 
else if (those)
{
    full_query = those_guys;   // <--- E1776 here
}

Using Visual Studio 2017, I'm getting the error

Error (active)  E1776   function "bsoncxx::v_noabi::builder::basic::document::operator=(const bsoncxx::v_noabi::builder::basic::document &) throw()" (declared implicitly) cannot be referenced -- it is a deleted function

It's my understanding from the documentation that I should be able to make this assignment. Please correct my thinking.


Solution

  • From the documentation:

    document & operator= (document &&doc) noexcept

    Move assignment operator.

    There's no mention of a copy assignment operator. Since a move assignment operator was defined the copy assignment operator is automatically deleted.

    So you have to use move assignment:

    full_query = std::move(these_guys);