Reputation: 40150
just what the title asks. I am trawling through some Ada code & came across
generic type X is (<>);
What does it mean? Is it something like a C++ template parameter?
Upvotes: 1
Views: 237
Reputation: 6430
A generic in Ada is either a package
, procedure
or function
,
with one or more formal parameters. A formal parameter can be an object, a type, a package or a subprogram. When instantiating a generic, you have to provide actuals for all the formal parameters.
generic
type X is (<>); -- formal parameter
procedure Foo(Item : in X);
In this declaration Foo
is the generic, and X
is a formal parameter. The (<>)
means that when you instantiate Foo
, the actual for X
must be of a discrete type (a signed integer type, a modular type, or an enumeration type):
procedure Bar is new Foo(Character);
Bar is now an instance of the generic procedure Foo
, and can be called with a parameter of type Character
:
Bar('@');
Upvotes: 6