首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译期间boost xml序列化失败

编译期间boost xml序列化失败
EN

Stack Overflow用户
提问于 2017-04-13 17:26:27
回答 1查看 954关注 0票数 1

我正在使用boost::icl::interval_map,以维护区间搜索树的城市和它的高,低温。我想将interval_map序列化为一个文件。

代码适用于文本和二进制序列化,但是xml序列化无法编译。这是我所犯的错误

代码语言:javascript
复制
root@ubuntu16:~/workspace/CPPCodes/interval-tree/city# make
g++ -o main  -std=c++14 -g -ggdb -O0 main.cpp -lboost_serialization
In file included from /usr/include/boost/mpl/aux_/na_assert.hpp:23:0,
                 from /usr/include/boost/mpl/arg.hpp:25,
                 from /usr/include/boost/mpl/placeholders.hpp:24,
                 from /usr/include/boost/archive/basic_binary_iprimitive.hpp:52,
                 from /usr/include/boost/archive/binary_iarchive_impl.hpp:21,
                 from /usr/include/boost/archive/binary_iarchive.hpp:20,
                 from main.cpp:4:
/usr/include/boost/archive/basic_xml_oarchive.hpp: In instantiation of ‘void boost::archive::basic_xml_oarchive<Archive>::save_override(T&, int) [with T = const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_oarchive]’:
/usr/include/boost/archive/detail/interface_oarchive.hpp:63:9:   required from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_oarchive]’
main.cpp:186:8:   required from here
/usr/include/boost/archive/basic_xml_oarchive.hpp:99:9: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************)’
         BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
         ^
/usr/include/boost/mpl/assert.hpp:83:5: note: candidate: template<bool C> int mpl_::assertion_failed(typename mpl_::assert<C>::type)
 int assertion_failed( typename assert<C>::type );
     ^
/usr/include/boost/mpl/assert.hpp:83:5: note:   template argument deduction/substitution failed:
/usr/include/boost/archive/basic_xml_oarchive.hpp:99:9: note:   cannot convert ‘mpl_::assert_arg<boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > > >(0u, 1)’ (type ‘mpl_::failed************ boost::serialization::is_wrapper<const boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************’) to type ‘mpl_::assert<false>::type {aka mpl_::assert<false>}’
         BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
         ^
/usr/include/boost/archive/basic_xml_iarchive.hpp: In instantiation of ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(T&, int) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’:
/usr/include/boost/archive/xml_iarchive.hpp:103:51:   required from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&, int) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:60:9:   required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> >; Archive = boost::archive::xml_iarchive]’
main.cpp:194:8:   required from here
/usr/include/boost/archive/basic_xml_iarchive.hpp:76:9: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************)’
         BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
         ^
/usr/include/boost/mpl/assert.hpp:83:5: note: candidate: template<bool C> int mpl_::assertion_failed(typename mpl_::assert<C>::type)
 int assertion_failed( typename assert<C>::type );
     ^
/usr/include/boost/mpl/assert.hpp:83:5: note:   template argument deduction/substitution failed:
/usr/include/boost/archive/basic_xml_iarchive.hpp:76:9: note:   cannot convert ‘mpl_::assert_arg<boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > > >(0u, 1)’ (type ‘mpl_::failed************ boost::serialization::is_wrapper<boost::icl::interval_map<long unsigned int, boost::container::flat_set<City> > >::************’) to type ‘mpl_::assert<false>::type {aka mpl_::assert<false>}’
         BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
         ^
Makefile:7: recipe for target 'main' failed
make: *** [main] Error 1

在编译过程中,以下BOOST_MPL_ASSERT失败

代码语言:javascript
复制
// Anything not an attribute and not a name-value pair is an
// error and should be trapped here.
template<class T>
void save_override(T & t, BOOST_PFTO int)
{
    // If your program fails to compile here, its most likely due to
    // not specifying an nvp wrapper around the variable to
    // be serialized.
    BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
    this->detail_common_oarchive::save_override(t, 0);
}

该评论建议,我没有使用NVP包装周围的成员被序列化。但是,我认为,对于所有成员变量,我都使用了BOOST_SERIALIZATION_NVPboost::serialization::make_nvp。不知道发生了什么。

代码被推到这里:failure/interval-tree/city

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-13 19:23:09

我认为,你的问题在一定程度上是对oarchive的重复。通过将oa << tree更改为oa << BOOST_SERIALIZATION_NVP(tree)来修正编译错误。我得到的结果输出存档是有意义的:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="14">
<tree class_id="0" tracking_level="0" version="0">
    <sz>1</sz>
    <INTERVAL class_id="1" tracking_level="0" version="0">
        <bb>2</bb>
        <l>28</l>
        <u>39</u>
    </INTERVAL>
    <SET class_id="2" tracking_level="0" version="0">
        <count>1</count>
        <item_version>0</item_version>
        <item class_id="3" tracking_level="0" version="0">
            <city_>cpur</city_>
            <low_>28</low_>
            <high_>39</high_>
        </item>
    </SET>
</tree>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43398330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档