Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does BOOST_SERIALIZATION_NVP do when serializing object?

I am using boost.serialization. some sample code use BOOST_SERIALIZATION_NVP in serialize method:

template<class Archive> void save(Archive & ar, const unsigned int version) const {    ar & BOOST_SERIALIZATION_NVP(_from_prop); } 

I tried to google its functionality but nothing useful is found. what is the diff between

 ar & BOOST_SERIALIZATION_NVP(_from_prop) 

and

 ar & _from_prop?  
like image 352
Shawn Avatar asked Dec 16 '11 09:12

Shawn


1 Answers

BOOST_SERIALIZATION_NVP is a macro that expands (in your example) to:

template<class Archive> void save(Archive & ar, const unsigned int version) const {     ar & boost::serialization::make_nvp("_from_prop", _from_prop) } 

make_nvp is a wrapper that acts the same as serializing directly as by

    ar & _from_prop; 

except when serializing to an XML archive. An XML archive needs some name to be used for the XML tag. This name is the name specified in the string parameter to make_nvp.

like image 59
Yakov Galka Avatar answered Sep 19 '22 21:09

Yakov Galka