[Ns-developers] NS3 Time objects
mathieu lacage
Mathieu.Lacage at sophia.inria.fr
Mon Oct 30 23:06:09 PST 2006
On Mon, 2006-10-30 at 22:41 +0000, Gustavo Carneiro wrote:
> On 10/30/06, George Riley <riley at ece.gatech.edu> wrote:
> On 10/30/06, George Riley <riley at ece.gatech.edu> wrote:
> > // 5) Multiplication or division of time objects by
> > other time objects
> > // is meaningless in ns3, and should not compile.
It is meaningful and it should compile. It is the only way to get this
to work. We already have the exact same problem with the return value of
operator - (arguably, not as dire): it returns a Time object even though
this object is most likely not what the Schedule method expects. So, in
a sense, we already allow the user to generate instances of Time objects
which cannot be passed to the Schedule method. As such, I am perfectly
comfortable with doing this again for operator * and operator /.
Redefining C++ operators is a tricky business and I had myself forgotten
how bad it is when I sent my first proposal arguing for a TimeDelta
object.
Generally speaking, trying to do what both of you are trying to do is
fraught with peril: it is not robust to try to mix and match multiple
types in operator signatures. I believe that we should stick to the
classic rule: "in doubt, make sure you behave like int or any arithmetic
type" which means that, in this case, operator / should return a Time
object and operator * should take two Time objects
The typical kind of problem you will run into is this:
time * factor / other_time
Here, classic operator rules allow you to re-order this expression to:
(time / other_time) * factor
or
time * (factor / other_time)
none of which make much sense if you try to do what you suggest. Yes, it
will not compile but I argue that it should and that it should give us
the same result in all 3 cases (modulo precision loss).
Mathieu
More information about the Ns-developers
mailing list