Book Image

D Cookbook

By : Adam Ruppe
Book Image

D Cookbook

By: Adam Ruppe

Overview of this book

Table of Contents (21 chapters)
D Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Determining names, types, and default values of function parameters


In the previous two recipes, we got a list of functions, including overloads and signatures in the form of types. To do really interesting things with function reflection, we need to dig into the details, isolating the return type and function parameters.

How to do it…

Let's execute the following steps to determine names, types, and default values of function parameters:

  1. Import std.traits. The Phobos module makes the task easier and is much more readable than the direct implementation.

  2. Get the function symbol. You may use the name directly (do not take the address of it, as we want to work on the function itself, and not on the pointer) by using __traits(getMember) or __traits(getOverloads).

  3. Isolate the return value with ReturnType!func. You may use this in any context in which you will use a type.

  4. Get the parameter types with ParameterTypeTuple!func. You may declare a variable with this type and fill arguments with it.

  5. Get the...