* pointer on an operator
@ 2004-03-18 14:32 Evangelista Sami
2004-03-18 14:58 ` Georg Bauhaus
0 siblings, 1 reply; 2+ messages in thread
From: Evangelista Sami @ 2004-03-18 14:32 UTC (permalink / raw)
hello
i have declared this type :
type bin_op is (plus_op, minus_op, div_op, mod_op, ...);
i want to make a function which takes a bin_op two integers and return
the result of the operation :
function get_bin_op_result(op : bin_op; left, right : integer) return
integer is
begin
case op is
when plus_op => return left + right;
when minus_op => return left - right;
...
end case;
end;
to avoid this, is there a way to make a function which return an
access to the right operator.like this :
type operator_access is access function(I1, I2 : Integer) return
Integer;
function get_operator(op : in bin_op) is
begin
case op is
when plus_op => return "+"'access;
when minus_op => return "-"'access;
...
end case;
end;
then the function simply becomes :
function get_bin_op_result(op : bin_op; left, right : integer) return
integer is
begin
return get_operator(op).all(left, right);
end;
i have tried this but the compilator complains on
"when plus_op => return "+"'access;" :
expressions.adb:299:17: expected type "Function_Access" defined at
line 296
expressions.adb:299:17: found type access to ""+"" defined at line 29
is there a way to do this?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: pointer on an operator
2004-03-18 14:32 pointer on an operator Evangelista Sami
@ 2004-03-18 14:58 ` Georg Bauhaus
0 siblings, 0 replies; 2+ messages in thread
From: Georg Bauhaus @ 2004-03-18 14:58 UTC (permalink / raw)
Evangelista Sami <evangeli@cnam.fr> wrote:
:
: i have tried this but the compilator complains on
: "when plus_op => return "+"'access;" :
:
: expressions.adb:299:17: expected type "Function_Access" defined at
: line 296
: expressions.adb:299:17: found type access to ""+"" defined at line 29
At first I thought you might rename "+" to "plus", say and then use
plus'Access, but "+" is intrinsic. But you can make inlined plus
wrapper functions and use access to these functions.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-03-18 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-18 14:32 pointer on an operator Evangelista Sami
2004-03-18 14:58 ` Georg Bauhaus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox