Boost logo

Boost :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2006-09-13 06:31:07


Can anyone see what's wrong with this example?

#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/shared_ptr.hpp>

template<typename value_t>
struct overflow_policy_base {
  overflow_policy_base (value_t _min, value_t _max) :
    min (_min), max (_max) {}
  virtual value_t apply (value_t) = 0;
  // virtual value_t apply (value_t);
  value_t min, max;

  friend class boost::serialization::access;

  template<class Archive>
  inline void serialize (Archive &ar, const unsigned int) {
    ar & this->min;
    ar & this->max;
  }
};

template<typename value_t>
struct limit_policy : public overflow_policy_base<value_t> {
  limit_policy (value_t _min, value_t _max) :
    overflow_policy_base<value_t> (_min, _max) {}

  virtual value_t apply (value_t x) {
    if (x > this->max)
      return this->max;
    else if (x < this->min)
      return this->min;
    else
      return x;
  }

  template<class Archive>
  inline void serialize (Archive &ar, const unsigned int) {
    ar & boost::serialization::base_object<overflow_policy_base<value_t> >(*this);
  }
};

template<typename value_t>
struct throw_policy : public overflow_policy_base<value_t> {
  throw_policy (value_t _min, value_t _max) :
    overflow_policy_base<value_t> (_min, _max) {}

  virtual value_t apply (value_t x) {
    if (x > this->max or x < this->min)
      throw std::runtime_error ("Histogram value out of range");
    else
      return x;
  }

  template<class Archive>
  inline void serialize (Archive &ar, const unsigned int) {
    ar & boost::serialization::base_object<overflow_policy_base<value_t> >(*this);
  }
};

#include <boost/serialization/export.hpp>
BOOST_SERIALIZATION_SHARED_PTR (limit_policy<double>)
  BOOST_CLASS_EXPORT_GUID (limit_policy<double>, "limit_policy<double>")

g++ -I /usr/local/src/boost.cvs -xc++ -fsyntax-only test.hpp
/usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp: In instantiation of ‘boost::serialization::type_info_implementation<limit_policy<double> >’:
/usr/local/src/boost.cvs/boost/serialization/export.hpp:76: instantiated from ‘boost::archive::detail::guid_initializer<limit_policy<double> >’
test.hpp:64: instantiated from here
/usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp:50: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_impl<limit_policy<double> >’
/usr/local/src/boost.cvs/boost/serialization/traits.hpp:42: error: declaration of ‘struct boost::serialization::extended_type_info_impl<limit_policy<double> >’


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk