Gem #11: Limited Types in Ada 2005 Constructor Functions Part 2 Author: Bob Duff, AdaCore Abstract: Ada Gem #11 We show here how limited constructor functions can be used in various contexts to build new limited objects in place. Let s get started ¦ We ve earlier seen examples of constructor functions for limited types similar to this: package P is type T (<>) is limited private; function Make_T (Name : String) return T; -- constructor function private type T is new Limited_Controlled with record ¦ end record; end P; package body P is function Make_T (Name : String) return T is begin return (Name => To_Unbounded_String (Name), others => <>); end Make_T; end P; function Make_Rumplestiltskin return T is begin return Make_T (Name => Rumplestiltskin ); end Make_Rumplestiltskin; It is useful to consider the various contexts in which these functions may be called. We ve already seen things like: Rumplestiltskin_Is_My_Name : T := Make_Rumplestiltskin; in which case the limited object is built directly in a standalone object. This object will be finalized whenever the surrounding scope is left. We can also do: procedure Do_Something (X : T); Do_Something (X => Make_Rumplestiltskin); Here, the result of
/lp/association-for-computing-machinery/gem-11-limited-types-in-ada-2005-constructor-functions-part-2-nK2k5mBDH9