boost::serialization optional does not use boost::serialization::access

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::serialization optional does not use boost::serialization::access

Boost - Dev mailing list
Hi, this simple program will not compile. The only way to make it
work is to make a public default constructor. This defeats the purpose
of boost::serialization::access.

I tried to fix <boost/serialization/optional.hpp> but I couldn't get
it to correctly call the access::construct();

Please help.

// g++ -o serialize_optional /tmp/serialize_optional.cpp -lboost_serialization

#include <fstream>
#include <iostream>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/optional.hpp>
#include <boost/optional.hpp>

class Foo {
        public:
                Foo(int k) : i(k) {}
                friend std::ostream& operator<<(std::ostream& os, Foo const& foo) {
                        return os << "Foo { " << foo.i << " }";
                }
        private:
                Foo() : i(-1) {};
                friend class boost::serialization::access;

                template<class Archive>
                void serialize(Archive & ar, const unsigned int){
                        #define N(a) BOOST_SERIALIZATION_NVP(a)
                        ar & N(i);
                        #undef N
                };
                int i;
};

int main() {
        using Data = boost::optional<Foo>;
        std::cout << "Boost version: " << BOOST_VERSION << "\n";
        {
                auto f = Data(133);
                std::ofstream os("test.xml");
                boost::archive::xml_oarchive oa(os);
                oa << boost::serialization::make_nvp("f", f);
        }
        {
                Data g;
                std::ifstream is("test.xml");
                boost::archive::xml_iarchive ia(is);
                ia >> boost::serialization::make_nvp("f", g);
               
                std::cout << g.get() << "\n";
        }
}




best regards
Janek Kozicki

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: boost::serialization optional does not use boost::serialization::access

Boost - Dev mailing list
On 7/21/19 1:24 PM, Janek Kozicki via Boost wrote:
> Hi, this simple program will not compile. The only way to make it
> work is to make a public default constructor. This defeats the purpose
> of boost::serialization::access.

please open up an issue in the serialization libary at github so we
don't lose track of it.

Robert Ramey


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: boost::serialization optional does not use boost::serialization::access

Boost - Dev mailing list
On 7/23/19 2:19 PM, Robert Ramey via Boost wrote:

> On 7/21/19 1:24 PM, Janek Kozicki via Boost wrote:
>> Hi, this simple program will not compile. The only way to make it
>> work is to make a public default constructor. This defeats the purpose
>> of boost::serialization::access.
>
> please open up an issue in the serialization libary at github so we
> don't lose track of it.
>
> Robert Ramey
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Speaking from memory,  I think the purpose of serialization::access is
to provide accesses to the serialization functions rather then all the
functions.  Also if memory serves me, this issue has come up before and
we went through some efforts to address it but in the end couldn't make
it work.  You might want to check the history of the serialization of
optional in git hub

Robert Ramey


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: boost::serialization optional does not use boost::serialization::access

Boost - Dev mailing list
Hi, thank you for your reply.

I created an issue: https://github.com/boostorg/serialization/issues/165
And a pull request: https://github.com/boostorg/serialization/pull/166

best regards
Janek Kozicki


Robert Ramey via Boost said:     (by the date of Tue, 23 Jul 2019 15:20:16 -0700)

> On 7/23/19 2:19 PM, Robert Ramey via Boost wrote:
> > On 7/21/19 1:24 PM, Janek Kozicki via Boost wrote:
> >> Hi, this simple program will not compile. The only way to make it
> >> work is to make a public default constructor. This defeats the purpose
> >> of boost::serialization::access.
> >
> > please open up an issue in the serialization libary at github so we
> > don't lose track of it.
> >
> > Robert Ramey
> >
> >
> > _______________________________________________
> > Unsubscribe & other changes:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
>
> Speaking from memory,  I think the purpose of serialization::access is
> to provide accesses to the serialization functions rather then all the
> functions.  Also if memory serves me, this issue has come up before and
> we went through some efforts to address it but in the end couldn't make
> it work.  You might want to check the history of the serialization of
> optional in git hub
>
> Robert Ramey

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: boost::serialization optional does not use boost::serialization::access

Boost - Dev mailing list
I managed to detect if there is a not public default constructor. So
now we have old (fast) behavior if there is a public constructor and
the workaround behavior if the constructor is private. So no loss in
performance.

Now the only problem is that it works only in C++17. We need to find
a way to make it work on older compilers.

https://github.com/boostorg/serialization/pull/166

I know it's still a long way to go. But we are closer to removing
this regression and restoring old behavior.

best regards
Janek


Janek Kozicki said:     (by the date of Wed, 24 Jul 2019 19:01:42 +0200)

> Hi, thank you for your reply.
>
> I created an issue: https://github.com/boostorg/serialization/issues/165
> And a pull request: https://github.com/boostorg/serialization/pull/166
>
> best regards
> Janek Kozicki
>
>
> Robert Ramey via Boost said:     (by the date of Tue, 23 Jul 2019 15:20:16 -0700)
>
> > On 7/23/19 2:19 PM, Robert Ramey via Boost wrote:
> > > On 7/21/19 1:24 PM, Janek Kozicki via Boost wrote:
> > >> Hi, this simple program will not compile. The only way to make it
> > >> work is to make a public default constructor. This defeats the purpose
> > >> of boost::serialization::access.
> > >
> > > please open up an issue in the serialization libary at github so we
> > > don't lose track of it.
> > >
> > > Robert Ramey
> > >
> > >
> > > _______________________________________________
> > > Unsubscribe & other changes:
> > > http://lists.boost.org/mailman/listinfo.cgi/boost
> > >
> >
> > Speaking from memory,  I think the purpose of serialization::access is
> > to provide accesses to the serialization functions rather then all the
> > functions.  Also if memory serves me, this issue has come up before and
> > we went through some efforts to address it but in the end couldn't make
> > it work.  You might want to check the history of the serialization of
> > optional in git hub
> >
> > Robert Ramey


--
# Janek Kozicki                              http://janek.kozicki.pl/

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost