Boost logo

Boost Users :

Subject: [Boost-users] boost::posix_time::time_period and boost::serialization
From: Lakin Wecker (lakin_at_[hidden])
Date: 2015-06-01 10:45:44


I'm having some issues getting the following example to compile in
g++4.9, or clang 3.6, using boost 1.58.0

I'm not quite experienced enough with boost or c++ to be certain, but it
appears that the vector serialization is done in such a way that it
doesn't pick up the load_construct_data for time_period from
boost/date_time/posix_time/time_serialize.hpp

Is the fix simply to do my own vector serialization a situation like
this? Or is there another fix?

Thank in advance,

Lakin

$ cat test.cpp

#include <boost/date_time/posix_time/time_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/serialization/vector.hpp>

#include <vector>
#include <sstream>

class test
{
public:

     friend class boost::serialization::access;

     std::vector<boost::posix_time::time_period> m_vec;

     template<class Archive>
     void serialize(Archive & ar, const unsigned int version)
     {
         ar & m_vec;
     }
};

int main(int argc, char *argv[]) {
     test a;

     std::ostringstream os;
     boost::archive::text_oarchive oa(os);
     oa << a;

     std::istringstream is(os.str());
     boost::archive::text_iarchive ia(is);
     ia >> a;

     std::cout << os.str() << std::endl;

     return 0;
}

$ g++ -std=c++14 test.cpp -I deps/boost_1_58_0

In file included from /usr/include/c++/4.9/memory:64:0,
                  from deps/boost_1_58_0/boost/config/no_tr1/memory.hpp:21,
                  from deps/boost_1_58_0/boost/smart_ptr/shared_ptr.hpp:23,
                  from deps/boost_1_58_0/boost/shared_ptr.hpp:17,
                  from
deps/boost_1_58_0/boost/date_time/gregorian/greg_month.hpp:14,
                  from
deps/boost_1_58_0/boost/date_time/gregorian/greg_ymd.hpp:16,
                  from
deps/boost_1_58_0/boost/date_time/gregorian/greg_calendar.hpp:16,
                  from
deps/boost_1_58_0/boost/date_time/gregorian/gregorian_types.hpp:19,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time_config.hpp:18,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time_system.hpp:13,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/ptime.hpp:12,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time.hpp:15,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/time_serialize.hpp:12,
                  from test.cpp:1:
/usr/include/c++/4.9/bits/stl_construct.h: In instantiation of ‘void
std::_Construct(_T1*, _Args&& ...) [with _T1 =
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>; _Args = {}]’:
/usr/include/c++/4.9/bits/stl_uninitialized.h:516:43: required from
‘static void
std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator,
_Size) [with _ForwardIterator =
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>*; _Size = long unsigned int; bool
_TrivialValueType = false]’
/usr/include/c++/4.9/bits/stl_uninitialized.h:571:33: required from
‘void std::__uninitialized_default_n(_ForwardIterator, _Size) [with
_ForwardIterator = boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>*; _Size = long unsigned int]’
/usr/include/c++/4.9/bits/stl_uninitialized.h:632:50: required from
‘void std::__uninitialized_default_n_a(_ForwardIterator, _Size,
std::allocator<_Tp>&) [with _ForwardIterator =
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>*; _Size = long unsigned int; _Tp =
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>]’
/usr/include/c++/4.9/bits/vector.tcc:549:39: required from ‘void
std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp,
_Alloc>::size_type) [with _Tp =
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>; _Alloc =
std::allocator<boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration> >; std::vector<_Tp, _Alloc>::size_type
= long unsigned int]’
/usr/include/c++/4.9/bits/stl_vector.h:676:41: required from ‘void
std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type)
[with _Tp = boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>; _Alloc =
std::allocator<boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration> >; std::vector<_Tp, _Alloc>::size_type
= long unsigned int]’
deps/boost_1_58_0/boost/serialization/vector.hpp:90:9: [ skipping 24
instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
deps/boost_1_58_0/boost/archive/detail/iserializer.hpp:618:24: required
from ‘void boost::archive::load(Archive&, T&) [with Archive =
boost::archive::text_iarchive; T = test]’
deps/boost_1_58_0/boost/archive/detail/common_iarchive.hpp:66:40:
required from ‘void
boost::archive::detail::common_iarchive<Archive>::load_override(T&, int)
[with T = test; Archive = boost::archive::text_iarchive]’
deps/boost_1_58_0/boost/archive/basic_text_iarchive.hpp:71:9: required
from ‘void
boost::archive::basic_text_iarchive<Archive>::load_override(T&, int)
[with T = test; Archive = boost::archive::text_iarchive]’
deps/boost_1_58_0/boost/archive/text_iarchive.hpp:92:57: required from
‘void boost::archive::text_iarchive_impl<Archive>::load_override(T&,
int) [with T = test; Archive = boost::archive::text_iarchive]’
deps/boost_1_58_0/boost/archive/detail/interface_iarchive.hpp:60:9:
required from ‘Archive&
boost::archive::detail::interface_iarchive<Archive>::operator>>(T&)
[with T = test; Archive = boost::archive::text_iarchive]’
test.cpp:36:11: required from here
/usr/include/c++/4.9/bits/stl_construct.h:75:7: error: no matching
function for call to ‘boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>::period()’
      { ::new(static_cast<void*>(__p))
_T1(std::forward<_Args>(__args)...); }
        ^
/usr/include/c++/4.9/bits/stl_construct.h:75:7: note: candidates are:
In file included from
deps/boost_1_58_0/boost/date_time/gregorian/gregorian_types.hpp:18:0,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time_config.hpp:18,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time_system.hpp:13,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/ptime.hpp:12,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/posix_time.hpp:15,
                  from
deps/boost_1_58_0/boost/date_time/posix_time/time_serialize.hpp:12,
                  from test.cpp:1:
deps/boost_1_58_0/boost/date_time/period.hpp:101:3: note:
boost::date_time::period<point_rep, duration_rep>::period(point_rep,
duration_rep) [with point_rep = boost::posix_time::ptime; duration_rep =
boost::posix_time::time_duration]
    period<point_rep,duration_rep>::period(point_rep first_point,
duration_rep len) :
    ^
deps/boost_1_58_0/boost/date_time/period.hpp:101:3: note: candidate
expects 2 arguments, 0 provided
deps/boost_1_58_0/boost/date_time/period.hpp:90:3: note:
boost::date_time::period<point_rep, duration_rep>::period(point_rep,
point_rep) [with point_rep = boost::posix_time::ptime; duration_rep =
boost::posix_time::time_duration]
    period<point_rep,duration_rep>::period(point_rep first_point,
    ^
deps/boost_1_58_0/boost/date_time/period.hpp:90:3: note: candidate
expects 2 arguments, 0 provided
deps/boost_1_58_0/boost/date_time/period.hpp:51:9: note: constexpr
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>::period(const
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>&)
    class period : private
          ^
deps/boost_1_58_0/boost/date_time/period.hpp:51:9: note: candidate
expects 1 argument, 0 provided
deps/boost_1_58_0/boost/date_time/period.hpp:51:9: note: constexpr
boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>::period(boost::date_time::period<boost::posix_time::ptime,
boost::posix_time::time_duration>&&)
deps/boost_1_58_0/boost/date_time/period.hpp:51:9: note: candidate
expects 1 argument, 0 provided


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net