What does BOOST_SERIALIZATION_NVP do when serializing object?

15,928

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.

Share:
15,928
Shawn
Author by

Shawn

Updated on June 15, 2022

Comments

  • Shawn
    Shawn almost 2 years

    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?