[odb-users] Problem using <complex>

Boris Kolpackov boris at codesynthesis.com
Fri May 5 06:50:06 EDT 2023


Andrew Cunningham <odb at a-cunningham.com> writes:

> Whenever I include <complex> in a header file to  be processed by ODB
> I get many of the following types of errors. I will be making the
> complex data member persistent.
> 
> [...]
> 
> I have been unable to come up with a workaround so far.

If upgrading to a later version of ODB is not an option here, I would
probably resort to emulating std::complex during the ODB compilation.
Something along these lines:

#ifndef ODB_COMPILER
#  include <complex>
#else
namespace std
{
  template <typename T>
  class complex
  {
    T re_;
    T im_;
    
  public:
    using value_type = T;

    complex(T re = T(), T im = T()): re_ (re), im_ (im) {}
    
    complex(const complex&) = default;   
    complex& operator=(const complex&) = default;

    T real() const {return re_;}
    void real(T re) {re_ = re;}
    T imag() const {return im_;}
    void imag(T im) {im_ = im;};
  };
}
#endif

You may also need to #ifdef-out any inline code that requires a proper
definition std::complex based on the ODB_COMPILER macro.



More information about the odb-users mailing list