View source code
							
							
						
								Display the source code in std/typecons.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Class std.typecons.AutoImplement
AutoImplement automatically implements (by default) all abstract member
functions in the class or interface Base in specified way.
						
				class AutoImplement(Base, alias how, alias what)
				
				  
				
				if (!is(how == class));
						
						
				class AutoImplement(Interface, BaseClass, alias how, alias what)
				
				  
				
				if (is(Interface == interface) && is(BaseClass == class));
						
					
				The second version of AutoImplement automatically implements
Interface, while deriving from BaseClass.
Methods
| Name | Description | 
|---|---|
| factory | Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor. | 
| opCmp | Compare with another Object obj. | 
| opEquals | Test whether thisis equal too.
 The default implementation only compares by identity (using theisoperator).
 Generally, overrides foropEqualsshould attempt to compare objects by their contents. | 
| toHash | Compute hash function for Object. | 
| toString | Convert Object to a human readable string. | 
Methods
| Name | Description | 
|---|---|
| factory | Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor. | 
| opCmp | Compare with another Object obj. | 
| opEquals | Test whether thisis equal too.
 The default implementation only compares by identity (using theisoperator).
 Generally, overrides foropEqualsshould attempt to compare objects by their contents. | 
| toHash | Compute hash function for Object. | 
| toString | Convert Object to a human readable string. | 
Parameters
| Name | Description | 
|---|---|
| how | template which specifies how functions will be implemented/overridden.
         Two arguments are passed to how: the typeBaseand an alias
         to an implemented function.  Thenhowmust return an implemented
         function body as a string.
         The generated function body can use these keywords:
 | 
| what | template which determines what functions should be
         implemented/overridden.
         An argument is passed to what: an alias to a non-final member
         function inBase.  Thenwhatmust return a boolean value.
         Returntrueto indicate that the passed function should be
         implemented/overridden.
--------------------
// Sees if fun returns something.
enum bool hasValue(alias fun) = !is(ReturnType!(fun) == void);
-------------------- | 
Note
Generated code is inserted in the scope of std module.  Thus,
any useful functions outside std cannot be used in the generated
code.  To workaround this problem, you may import necessary things in a
local struct, as done in the generateLogger() template in the above
example.
BUGS
- Variadic arguments to constructors are not forwarded to super.
- Deep interface inheritance causes compile error with messages like "Error: function std.typecons.AutoImplement!(Foo).AutoImplement.bar does not override any function". [Bugzilla 2525]
- The parentkeyword is actually a delegate to the super class' corresponding member function. [Bugzilla 2540]
- Using alias template parameter in howand/orwhatmay cause strange compile error. Use template tuple parameter instead to workaround this problem. [Bugzilla 4217]
Example
interface PackageSupplier
{
    int foo();
    int bar();
}
static abstract class AbstractFallbackPackageSupplier : PackageSupplier
{
    protected PackageSupplier default_, fallback;
    this(PackageSupplier default_, PackageSupplier fallback)
    {
        thisAuthors
Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.