gpt4 book ai didi

opencl - 通过自定义函数 : "static assertion failed::typex::value" 序列化联合类型

转载 作者:行者123 更新时间:2023-12-05 00:35:07 24 4
gpt4 key购买 nike

我正在连载 cl_long2来自 OpenCL 的类型定义如下(从 /usr/include/CL/cl_platform.hpp 简化):

typedef int64_t cl_long;
typedef union
{
cl_long __attribute__ ((aligned(16))) s[2];
struct{ cl_long x, y; };
struct{ cl_long s0, s1; };
struct{ cl_long lo, hi; };
} cl_long2;

我定义了以下独立的序列化函数:
namespace boost{ namespace serialization {
template<class Archive> void serialize(Archive &ar, cl_long2 &i, const unsigned version){
ar & make_nvp("x",i.x);
ar & make_nvp("y",i.y);
}

}};

当我编译我的代码时,它作为类成员调用 cl_long2 的序列化,我收到以下错误,我无法理解(如果它不是 std::vector<cl_long2> ,错误是相同的,只是一个独立变量):
/usr/include/boost/archive/detail/check.hpp: In function ‘void boost::archive::detail::check_object_level() [with T = cl_long2]’:
/usr/include/boost/archive/detail/iserializer.hpp:438:9: instantiated from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = cl_long2, Archive = boost::archive::xml_iarchive]’
/usr/include/boost/archive/detail/iserializer.hpp:592:5: instantiated from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::xml_iarchive, T = cl_long2]’
/usr/include/boost/archive/detail/common_iarchive.hpp:66:9: instantiated from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&, int) [with T = cl_long2, Archive = boost::archive::xml_iarchive]’
/usr/include/boost/archive/basic_xml_iarchive.hpp:86:9: instantiated from ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&, int) [with T = cl_long2, Archive = boost::archive::xml_iarchive]’
/usr/include/boost/archive/xml_iarchive.hpp:93:9: instantiated from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&, int) [with T = const boost::serialization::nvp<cl_long2>, Archive = boost::archive::xml_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:60:9: [ skipping 5 instantiation contexts ]
/usr/include/boost/serialization/split_free.hpp:58:9: instantiated from ‘static void boost::serialization::free_loader<Archive, T>::invoke(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = std::vector<cl_long2>]’
/usr/include/boost/serialization/split_free.hpp:74:5: instantiated from ‘void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = std::vector<cl_long2>]’
/usr/include/boost/serialization/vector.hpp:151:5: instantiated from ‘void boost::serialization::serialize(Archive&, std::vector<U, Allocator>&, unsigned int) [with Archive = boost::archive::xml_iarchive, U = cl_long2, Allocator = std::allocator<cl_long2>]’
/usr/include/boost/serialization/serialization.hpp:128:9: instantiated from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive, T = std::vector<cl_long2>]’
/usr/include/boost/archive/detail/iserializer.hpp:188:5: instantiated from ‘void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive, T = std::vector<cl_long2>]’
myFile.cpp:368:2: instantiated from here
/usr/include/boost/archive/detail/check.hpp:60:5: error: static assertion failed: "typex::value"

无论存档类型是 xml 还是二进制,都会出现相同的错误。我正在使用 boost::serialization 1.46。

任何提示?

**编辑:包含错误的较小示例位于 http://ideone.com/4UgCn

最佳答案

如果您查看断言失败的行 (detail/check.hpp:60),则会在其正上方有一条注释:

// trap attempts to serialize objects marked
// not_serializable
BOOST_STATIC_ASSERT(typex::value);

documentation of this 'not_serializable' trait说你必须启用这个 long2先打字。正如您所发现的,这是通过以下方式完成的:
BOOST_CLASS_IMPLEMENTATION(long2,boost::serialization::object_serializable)

关于opencl - 通过自定义函数 : "static assertion failed::typex::value" 序列化联合类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9777387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com