It cannot be used because the _callback member is of type std::unique_ptr.
Regarding Query::ChangeListener, it seems strange that the Query::ChangeListener owns the query and not the other way around, more so that Query::ChangeListener doesn’t have a working assign operator.
These wrappers work fine in simple sopes, but I find a bit complicated and unintuitive to manage a ChangeListener object, I don’t know if other users have this problem too.
@Ionut_Cosmin_Mihai : It would be quite helpful if you could give us just some basic information about your use caae. This is Couchbase Lite C? A recent version? You are building with, maybe, clang?
Yes, this is Couchbase Lite C, last master commit wich today is 6e033f5d9b21c92ad6e04819987b6325d6cb59ac . The implementation is the same on release/lithium.
The compiler I usd is MSVC(we are also using clang) but copying a std::unique_ptr doesn’t work on any compiler.
Here is the case (This will not compile, so I am referring to building only, not to functionality.):
class QueryManager
{
public:
ReplicatorManager() = default;
~ReplicatorManager() = default;
void createQuery(cbl::Database& database)
{
q = cbl::Query(database, kCBLN1QLLanguage, "REQUEST EXAMPLE");
// This will result in:
// Error C2280 'std::unique_ptr<std::function<void (cbl::Query::Change)>,std::default_delete<std::function<void (cbl::Query::Change)>>> &std::unique_ptr<std::function<void (cbl::Query::Change)>,std::default_delete<std::function<void (cbl::Query::Change)>>>::operator =(const std::unique_ptr<std::function<void (cbl::Query::Change)>,std::default_delete<std::function<void (cbl::Query::Change)>>> &)': attempting to reference a deleted function ConsoleApplicationCouchbase include\cbl++\Base.hh
// This error can be workedaround by having instead a std::shared_ptr<cbl::Query::ChangeListener>
changeListener = q.addChangeListener([](cbl::Query::Change change) {
std::cout << "Print something on change";
});
// Next, if we look into the addChangeListener implementation we see that the ownership of q is given to the Query::ChangeListener object. Before the addChangeListener call is finished, q is not owned by this class, but by the changeListener member.
}
private:
cbl::Query q;
cbl::Query::ChangeListener changeListener;
};
I think it is a common case to manage a query object like this(maybe having a map of queries), I am wondering if it is supposed to be used in another way. Also it is not clear for me how the objects should be destroyed in this case.
Thanks for help!