Ticket #4179: boost.timeDurationArithmeticOnTickType.diff

File boost.timeDurationArithmeticOnTickType.diff, 4.3 KB (added by Michał Ślizak, 9 years ago)

Changed multiplication and division to accept 'tick_type' instead of 'int'

  • boost/date_time/int_adapter.hpp

    diff -pru boost-1.41.0.cmake0.orig/boost/date_time/int_adapter.hpp boost-1.41.0.cmake0/boost/date_time/int_adapter.hpp
    old new public:  
    134134  {
    135135    return (compare(rhs) == 0);
    136136  }
    137   bool operator==(const int& rhs) const
     137  bool operator==(const int_type& rhs) const
    138138  {
    139139    // quiets compiler warnings
    140140    bool is_signed = std::numeric_limits<int_type>::is_signed;
    public:  
    151151  {
    152152    return (compare(rhs) != 0);
    153153  }
    154   bool operator!=(const int& rhs) const
     154  bool operator!=(const int_type& rhs) const
    155155  {
    156156    // quiets compiler warnings
    157157    bool is_signed = std::numeric_limits<int_type>::is_signed;
    public:  
    168168  {
    169169    return (compare(rhs) == -1);
    170170  }
    171   bool operator<(const int& rhs) const
     171  bool operator<(const int_type& rhs) const
    172172  {
    173173    // quiets compiler warnings
    174174    bool is_signed = std::numeric_limits<int_type>::is_signed;
  • boost/date_time/time_duration.hpp

    diff -pru boost-1.41.0.cmake0.orig/boost/date_time/time_duration.hpp boost-1.41.0.cmake0/boost/date_time/time_duration.hpp
    old new namespace date_time {  
    164164    {
    165165      return duration_type(ticks_ + d.ticks_);
    166166    }
    167     duration_type operator/(long long divisor) const
     167    duration_type operator/(tick_type divisor) const
    168168    {
    169169      return duration_type(ticks_ / divisor);
    170170    }
    namespace date_time {  
    179179      return duration_type(ticks_);
    180180    }
    181181    //! Division operations on a duration with an integer.
    182     duration_type operator/=(long long divisor)
     182    duration_type operator/=(tick_type divisor)
    183183    {
    184184      ticks_ = ticks_ / divisor;
    185185      return duration_type(ticks_);
    186186    }
    187187    //! Multiplication operations an a duration with an integer
    188     duration_type operator*(long long rhs) const
     188    duration_type operator*(tick_type rhs) const
    189189    {
    190190      return duration_type(ticks_ * rhs);
    191191    }
    192     duration_type operator*=(long long divisor)
     192    duration_type operator*=(tick_type divisor)
    193193    {
    194194      ticks_ = ticks_ * divisor;
    195195      return duration_type(ticks_);
  • libs/date_time/test/posix_time/testduration.cpp

    diff -pru boost-1.41.0.cmake0.orig/libs/date_time/test/posix_time/testduration.cpp boost-1.41.0.cmake0/libs/date_time/test/posix_time/testduration.cpp
    old new main()  
    6161                                 t_5.fractional_seconds() == 5));
    6262  t_5 = time_duration(3,15,8,0) / 2;
    6363  check("divide int", t_5 == time_duration(1,37,34,0));
    64   t_5 = time_duration(1000000, 0, 0, 0);
    65   t_5 /= 3600000000LL;
    66   check("divide equal long long", time_duration(0, 0, 1, 0) == t_5);
    67   t_5 = time_duration(1000000, 0, 0, 0) / 3600000000LL;
    68   check("divide long long", time_duration(0, 0, 1, 0) == t_5);
    6964  {
    7065    time_duration td = hours(5);
    7166    td *= 5;
    7267    check("mult-equals int", time_duration(25,0,0,0) == td);
    7368  }
    74   t_5 = time_duration(0, 0, 1, 0);
    75   t_5 *= 3600000000LL;
    76   check("multiply equals long long", time_duration(1000000, 0, 0, 0) == t_5);
    77   t_5 = time_duration(0, 0, 1, 0) * 3600000000LL;
    78   check("multiply long long", time_duration(1000000, 0, 0, 0) == t_5);
     69  if (sizeof(time_duration::tick_type) == 8)
     70  {
     71    std::cout << "testing time_duration 64-bit multiplication and division" << std::endl;
     72    t_5 = time_duration(0, 0, 1, 0);
     73    t_5 *= 3600000000LL;
     74    check("multiply equals long long", time_duration(1000000, 0, 0, 0) == t_5);
     75    t_5 = time_duration(0, 0, 1, 0) * 3600000000LL;
     76    check("multiply long long", time_duration(1000000, 0, 0, 0) == t_5);
     77    t_5 = time_duration(1000000, 0, 0, 0);
     78    t_5 /= 3600000000LL;
     79    check("divide equal long long", time_duration(0, 0, 1, 0) == t_5);
     80    t_5 = time_duration(1000000, 0, 0, 0) / 3600000000LL;
     81    check("divide long long", time_duration(0, 0, 1, 0) == t_5);
     82  }
    7983 
    8084  t_5 = t_2 + t_1;
    8185  //VC6 goes ambiguous on the next line...