octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conversion of octave_int<short int> to int? moved from help-octave


From: John W. Eaton
Subject: Re: conversion of octave_int<short int> to int? moved from help-octave
Date: Wed, 14 Nov 2007 17:25:55 -0500

On 13-Nov-2007, Eric Chassande-Mottin wrote:

| thanks for your note,
| 
| > In any case, I think having functions for this is better than using
| > conversion operators because the functions can't be invoked
| > automatically, so you are forced to think about the type conversions
| > that you are making.
| >
| > If you'd like to discuss how this should be implemented, please start
| > a discussion on the maintainers list.
| 
| my programming skills in C++ are limited and I don't have a strong preference.
| just the feeling that although functions make sense when dealing with
| containers like vectors or matrices, they might be a syntax overkill
| for scalars.
| the simple expression above would become
| 
| int arcIndex = arcs(k).int_value()  - 1;
| 
| more complicated expressions are likely to be difficult to read.

If we are going to have conversion operators, I think maybe they
should be limited to

  operator () T (void) const { return value (); }

For now, I've added this operator to the octave_int class.  I have not
removed the other conversions (bool, char, double, float), but they
might be deleted in some future version of Octave.

Does it help you to have this conversion operator?

jwe


2007-11-14  John W. Eaton  <address@hidden>

        * oct-inttypes.h (opeator T (void) const): New conversion operator.


Index: liboctave/oct-inttypes.h
===================================================================
RCS file: /cvs/octave/liboctave/oct-inttypes.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -u -r1.32 -r1.33
--- liboctave/oct-inttypes.h    12 Oct 2007 21:27:16 -0000      1.32
+++ liboctave/oct-inttypes.h    14 Nov 2007 22:21:35 -0000      1.33
@@ -250,6 +250,8 @@
       OCTAVE_INT_FIT_TO_RANGE (- static_cast<double> (ival), T) : 0;
   }
 
+  operator T (void) const { return value (); }
+
   operator bool (void) const { return static_cast<bool> (value ()); }
 
   operator char (void) const { return static_cast<char> (value ()); }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]