Summary

This lesson provides a summary of the concepts covered in this chapter.

We'll cover the following

Chapter summary

  • The return type of an auto function is deduced automatically.

  • The return value of a ref function is a reference to an existing variable.

  • The return value of an auto ref function is a reference if possible, a copy otherwise.

  • inout carries the const, immutable, or mutable attribute of the parameter to the return type.

  • A pure function cannot access mutable global or static state. The compiler infers the purity of templates, delegates, anonymous functions, and auto functions.

  • @nogc functions cannot involve GC operations.

  • @safe functions cannot corrupt memory. The compiler infers the safety attributes of templates, delegates, anonymous functions, and auto functions.

  • @trusted functions are indeed safe but cannot be specified as such; they are considered @safe both by the programmer and the compiler.

  • @system functions can use every D feature. @system is the default safety attribute.

  • Functions can be executed at compile time (CTFE) as well. This can be differentiated by the value of the special variable __ctfe.


Get hands-on with 1000+ tech skills courses.