Opened 9 years ago

Closed 7 years ago

#828 closed request (fixed)

try convert string to numeric type

Reported by: Peter Owned by: Peter
Priority: minor Milestone: yat 0.15
Component: utility Version:
Keywords: Cc:


There is the convert function to convert a string to numeric type and there is the is function to check if a string can be converted to a numeric type.

Smetimes you don't know if your string can be converted, but if it can you want to convert it. Rather than writing something like

int x=0;
if (is<int>(str))
  x = convert<int>(str);

it would be better to write something like

int x=0;
try_convert<int>(str, x);

I think the function already is implemented as a private function. Function try_convert should perhaps return bool` as an indication whether str was converted or not.

Change History (3)

comment:1 Changed 7 years ago by Peter

Milestone: yat 0.x+yat 0.15

comment:2 Changed 7 years ago by Peter

Owner: changed from Jari Häkkinen to Peter
Status: newassigned

comment:3 Changed 7 years ago by Peter

Resolution: fixed
Status: assignedclosed

(In [3597]) closes #828, function convert_try

Note: See TracTickets for help on using tickets.