问题描述
我正在尝试使用ODB,但是我遇到了关于std :: atomic的错误。 我读过这里:the same problem on odb mailing list 因此,我尝试在wrapper-traits.hxx文件中为std :: atomic定义odb :: wrapper_traits专长。 我通过添加:
// Specialization for odb::atomic.
template <typename T>
class wrapper_traits< std::atomic<T> >
{
public:
// T can be const.
//
typedef T wrapped_type;
typedef nullable<T> wrapper_type;
// T can be const.
//
typedef
typename odb::details::meta::remove_const<T>::result
unrestricted_wrapped_type;
static const bool null_handler = true;
static const bool null_default = true;
static bool
get_null (const wrapper_type& n)
{
return n.null ();
}
static void
set_null (wrapper_type& n)
{
n.reset ();
}
static const wrapped_type&
get_ref (const wrapper_type& n)
{
return *n;
}
static unrestricted_wrapped_type&
set_ref (wrapper_type& n)
{
if (n.null ())
n = unrestricted_wrapped_type ();
return const_cast<unrestricted_wrapped_type&> (*n);
}
};
但是当我尝试获取我的shema时,仍然有一个错误(使用:odb -d -v mysql --generate-query --generate-schema * .h):
/usr/local/include/odb/wrapper-traits.hxx:277:30: error: ‘atomic’ is not a member of ‘std’
有人可以帮我吗? 哈维尔。
解决方法
最后,我使用其他方式:我在使用虚拟数据成员
#pragma db transient
std::atomic<double> valAtom;
#pragma db member(valAtom_) virtual(double) \
get(this.valAtom.load (std::memory_order_relaxed)) \
set(this.valAtom.store ((?),std::memory_order_relaxed))
并且(感谢jignatius)我在odb命令中使用了--std c ++ 11。 很好!