Az Ada 2005 programozási nyelv

Sablonok

Szintaxis

Generic-ek deklarációjának a szintaxisa a következő:
generic_declaration ::= generic_subprogram_declaration | generic_package_declaration

generic_subprogram_declaration ::= generic_formal_part subprogram_specification;

generic_package_declaration ::= generic_formal_part package_specification;

generic_formal_part ::= generic {generic_formal_parameter_declaration | use_clause}

generic_formal_parameter_declaration ::=
  formal_object_declaration
  | formal_type_declaration
  | formal_subprogram_declaration
  | formal_package_declaration

Részletesebben itt olvashat a témáról:

Paraméterek

A generic lehetséges paramétereivel kapcsolatban a következő linkek lesznek segítségére:

Példányosítás

A következő sorokban a generic példánosításának a szintaxisát olvashatjuk:
generic_instantiation ::=
  package defining_program_unit_name is
    new generic_package_name [generic_actual_part];
  | [overriding_indicator]
  procedure defining_program_unit_name is
    new generic_procedure_name [generic_actual_part];
  | [overriding_indicator]
  function defining_designator is
    new generic_function_name [generic_actual_part];

generic_actual_part ::=
  (generic_association {, generic_association})

generic_association ::=
  [generic_formal_parameter_selector_name =>] explicit_generic_actual_parameter

explicit_generic_actual_parameter ::= expression | variable_name
  | subprogram_name | entry_name | subtype_mark
  | package_instance_name

Példák:

  procedure Swap is new Exchange(Elem => Integer);
  procedure Swap is new Exchange(Character);
  function Square is new Squaring(Integer);
  function Square is new Squaring(Item => Matrix, "*" => Matrix_Product);
  function Square is new Squaring(Matrix, Matrix_Product);

Részletek a következő linkeken találhat: