[odb-users] use of unique_ptr in odb::connection::cache_query
Quentin Deldycke
quentindeldycke at gmail.com
Fri Feb 21 12:38:05 EST 2020
Hi,
Using odb 2.4.0 I was using this code (c++-98)
static void histoSearch(const char* name, odb::connection& c)
{
// This is my parameter class
typedef ScherzoConfigurationImpression::HistoParams param;
// This one is a view
typedef ScherzoConfigurationImpression::CI_HistoImpression base;
typedef odb::query<base> qry;
typedef odb::prepared_query<base> pqry;
std::auto_ptr<param> p(new
param);
// Creation query
qry q(qry::form == qry::_ref(p->form) &&
qry::dest == qry::_ref(p->dest) &&
qry::idform == qry::_ref(p->idform));
pqry pq(c.prepare_query<base>(name, q));
// We put to cache
c.cache_query(pq, p);
}
Now, with odb 2.5.0 and c++-11, i need to use it like this:
static void histoSearch(const char* name, odb::connection& c)
{
// This is my parameter class
typedef ScherzoConfigurationImpression::HistoParams param;
// This one is a view
typedef ScherzoConfigurationImpression::CI_HistoImpression base;
typedef odb::query<base> qry;
typedef odb::prepared_query<base> pqry;
std::unique_ptr<param> p =
std::make_unique<param>();
// Creation query
qry q(qry::form == qry::_ref(p->form) &&
qry::dest == qry::_ref(p->dest) &&
qry::idform == qry::_ref(p->idform));
pqry pq(c.prepare_query<base>(name, q));
// We put to cache
c.cache_query(pq, p);
}
But the new version does not work:
configurationimpressionrunnable.cpp: In function 'void histoSearch(const
char*, odb::connection&)':
configurationimpressionrunnable.cpp:486:24: error: use of deleted function
'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&)
[with _Tp = ScherzoConfigurationImpression::HistoParams; _Dp =
std::default_delete<ScherzoConfigurationIm
pression::HistoParams>]'
c.cache_query(pq, p);
^
In file included from /usr/include/c++/8/memory:80,
from configurationimpressionrunnable.hpp:4,
from configurationimpressionrunnable.cpp:1:
/usr/include/c++/8/bits/unique_ptr.h:394:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
^~~~~~~~~~
In file included from /usr/local/include/odb/connection.hxx:223,
from /usr/local/include/odb/database.hxx:29,
from ../../../include/views/viewconnection.hpp:6,
from ../../../include/views/scherzorunnable.hpp:5,
from ../../../include/views/xdrrunnable.hpp:4,
from configurationimpressionrunnable.hpp:8,
from configurationimpressionrunnable.cpp:1:
/usr/local/include/odb/connection.ixx:69:15: note: initializing argument
2 of 'void odb::connection::cache_query(const odb::prepared_query<T>&,
std::unique_ptr<P>) [with T =
ScherzoConfigurationImpression::CI_HistoImpression; P =
ScherzoConfigurationI
mpression::HistoParams]'
inline void connection::
^~~~~~~~~~
Which actually seems logic. But the cache_query function does not provide
other signatures.
--
Deldycke Quentin
More information about the odb-users
mailing list