object
Forms the symbols available to all D programs. Includes Object, which is the root of the class object hierarchy. This module is implicitly imported.
Copyright
Types 36
Bottom type. See spec/type.
All D class objects inherit from Object.
string toString()Convert Object to a human readable string.int opCmp(Object o)Compare with another Object obj. Returns: this < obj < 0 this == obj 0 this > obj > 0bool opEquals(Object o)Test whether this is equal to o. The default implementation only compares by identity (using the is operator). Generally, overrides and overloads for opEquals should attempt to compare objects by t...Object factory(string classname)Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor. Returns: null if failed Example: --- module foo.bar;Information about an interface. When an object is accessed via an interface, an Interface* appears as the first entry in its vtbl.
TypeInfo_Class classinfoClass info returned by `typeid` for this interface (not for containing class)void *[] vtblsize_t offsetArray of pairs giving the offset and type information for each member in an aggregate.
Runtime type information about a type. Can be retrieved for any type using a expression,TypeidExpression, TypeidExpression.
int opCmp(Object rhs)bool opEquals(Object o)size_t getHash(scope const void * p) @trusted nothrow constComputes a hash of the instance of a type. Params: p = pointer to start of instance of the type Returns: the hash Bugs: fix https://issues.dlang.org/show_bug.cgi?id=12516 e.g. by changing this to a...inout(TypeInfo) next() @property nothrow pure inout @nogcGet TypeInfo for 'next' type, as defined by what kind of type this is, null if none.const(void)[] initializer() nothrow pure const @safe @nogcReturn default initializer. If the type should be initialized to all zeros, an array with a null ptr and a length equal to the type size will be returned. For static arrays, this returns the defau...uint flags() @property nothrow pure const @safe @nogcGet flags for type: 1 means GC should scan for pointers, 2 means arg of this type is passed in SIMD register(s) if availableconst(OffsetTypeInfo)[] offTi() constGet type information on the contents of the type; null if not availableimmutable(void) * rtInfo() @property nothrow pure const @trusted @nogcReturn info used by the garbage collector to do precise collection.bool opEquals(Object o)size_t getHash(scope const void * p) constbool equals(in void * p1, in void * p2) constint compare(in void * p1, in void * p2) constvoid swap(void * p1, void * p2) constconst(OffsetTypeInfo)[] offTi() constvoid destroy(void * p) constvoid postblit(void * p) constconst(void)[] initializer() constRuntime type information about a class. Can be retrieved from an object instance by using the
spec/expression.byte[] m_initstring namevoid *[] vtblInterface[] interfacesTypeInfo_Class basevoid * destructorvoid function(Object) classInvariantClassFlags m_flagsushort depthvoid * deallocatorOffsetTypeInfo[] m_offTivoid function(Object) defaultConstructorimmutable(void) * m_RTInfouint[4] nameSigbool equals(in void * p1, in void * p2) constint compare(in void * p1, in void * p2) constconst(TypeInfo_Class) find(const scope char[] classname)Search all modules for TypeInfo_Class corresponding to classname. Returns: null if not foundbool isBaseOf(scope const TypeInfo_Class child) const @nogc nothrow pure @trustedReturns true if the class described by `child` derives from or is the class described by this `TypeInfo_Class`. Always returns false if the argument is null.ClassFlagsTypeInfo_Class infobool opEquals(Object o)bool equals(in void * p1, in void * p2) constint compare(in void * p1, in void * p2) constbool isBaseOf(scope const TypeInfo_Class child) const @nogc nothrow pure @trustedReturns true if the class described by `child` derives from the interface described by this `TypeInfo_Interface`. Always returns false if the argument is null.bool isBaseOf(scope const TypeInfo_Interface child) const @nogc nothrow pure @trustedReturns true if the interface described by `child` derives from or is the interface described by this `TypeInfo_Interface`. Always returns false if the argument is null.string mangledNamevoid[] m_initsize_t function(in void *) xtoHashbool function(in void *, in void *) xopEqualsint function(in void *, in void *) xopCmpstring function(in void *) xtoStringStructFlags m_flagsvoid function(void *) xpostblituint m_alignimmutable(void) * m_RTInfostring toString() constsize_t toHash() constbool opEquals(Object o)void destroy(void * p) constvoid postblit(void * p) const_memberFuncTypeInfo[] elementsstring toString() conststring toString() conststring toString() constAn instance of ModuleInfo is generated into the object file for each compiled module.
It provides access to various aspects of the module. It is not generated for betterC.
uint _flagsuint _indexvoid function() tlsctor() @property nothrow pure @nogcReturns: module constructor for thread locals, `null` if there isn't onevoid function() tlsdtor() @property nothrow pure @nogcReturns: module destructor for thread locals, `null` if there isn't onevoid * xgetMembers() @property nothrow pure @nogcReturns: address of a module's `const(MemberInfo)[] getMembers(string)` function, `null` if there isn't onevoid function() ctor() @property nothrow pure @nogcReturns: module constructor, `null` if there isn't onevoid function() dtor() @property nothrow pure @nogcReturns: module destructor, `null` if there isn't onevoid function() ictor() @property nothrow pure @nogcReturns: module order independent constructor, `null` if there isn't onevoid function() unitTest() @property nothrow pure @nogcReturns: address of function that runs the module's unittests, `null` if there isn't oneimmutable(ModuleInfo *)[] importedModules() @property return nothrow pure @nogcReturns: array of pointers to the ModuleInfo's of modules imported by this oneTypeInfo_Class[] localClasses() @property return nothrow pure @nogcReturns: array of TypeInfo_Class references for classes defined in this moduleint opApply(scope int delegate(ModuleInfo *) dg)The base class of all thrown objects.
All thrown objects must inherit from Throwable. Class Exception, which derives from this class, represents the category of thrown objects that are safe to catch and handle. In principle, one should not catch Throwable objects that are not derived from Exception, as they represent unrecoverable runtime errors. Certain runtime guarantees may fail to hold when these errors are thrown, making it unsafe to continue execution after catching them.
string msgstring fileThe file name of the D source code corresponding with where the error was thrown from.size_t lineThe line number of the D source code corresponding with where the error was thrown from.TraceInfo infoThe stack trace of where the error happened. This is an opaque object that can either be converted to string, or iterated over with foreach to extract the items in the stack trace (as strings).TraceDeallocator infoDeallocatorIf set, this is used to deallocate the TraceInfo on destruction.private void * _nextInChainPtrA reference to the next error in the list. This is used when a new Throwable is thrown from inside a catch block. The originally caught Exception will be chained to the new Throwable via this field.private uint _refcountinout(Throwable) next() @property @trusted inout return scope pure nothrow @nogcReturns: A reference to the next error in the list. This is used when a new Throwable is thrown from inside a catch block. The originally caught Exception will be chained to the new Throwable via t...void next(Throwable tail) @property @trusted scope pure nothrow @nogcReplace next in chain with `tail`. Use `chainTogether` instead if at all possible.uint refcount() @system @nogc pure nothrow ref returnReturns: mutable reference to the reference count, which is 0 - allocated by the GC, 1 - allocated by dnewThrowable(), and >=2 which is the reference count + 1 Note: Marked as `@system` to discoura...int opApply(scope int delegate(Throwable) dg)Loop over the chain of Throwables.Throwable chainTogether(return scope Throwable e1, return scope Throwable e2) @__future @system @nogc pure nothrowAppend `e2` to chain of exceptions that starts with `e1`. Params: e1 = start of chain (can be null) e2 = second part of chain (can be null) Returns: Throwable that is at the start of the chain; nul...string toString()Overrides Object.toString and returns the error message. Internally this forwards to the toString overload that takes a sink delegate.void toString(scope void delegate(in char[]) sink) constThe Throwable hierarchy uses a toString overload that takes a sink delegate to avoid GC allocations, which cannot be performed in certain error situations. Override this toString method to customi...this(string msg, Throwable nextInChain = null)this(string msg, string file, size_t line, Throwable nextInChain = null)The base class of all errors that are safe to catch and handle.
In principle, only thrown objects derived from this class are safe to catch inside a catch block. Thrown objects not derived from Exception represent runtime errors that should not be caught, as certain runtime guarantees may not hold, making it unsafe to continue program execution.
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null)Creates a new instance of Exception. The nextInChain parameter is used internally and should always be null when passed by user code. This constructor does not automatically throw the newly-created...this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__)The base class of all unrecoverable runtime errors.
This represents the category of Throwable objects that are not safe to catch and handle. In principle, one should not catch Error objects, as they represent unrecoverable runtime errors. Certain runtime guarantees may fail to hold when these errors are thrown, making it unsafe to continue execution after catching them.
Throwable bypassedExceptionThe first Exception which was bypassed when this Error was thrown, or null if no Exceptions were pending.this(string msg, Throwable nextInChain = null)Creates a new instance of Error. The nextInChain parameter is used internally and should always be null when passed by user code. This constructor does not automatically throw the newly-created Err...this(string msg, string file, size_t line, Throwable nextInChain = null)void * ptrFunctions 52
bool opEquals(LHS, RHS)(LHS lhs, RHS rhs) if ((is(LHS : const Object) || is(LHS : const shared Object)) &&
(is(RHS : const Object) || is(RHS : const shared Object)))Implementation for class opEquals override. Calls the class-defined methods after a null check. Please note this is not nogc right now, even if your implementation is, because of the typeinfo name ...void setSameMutex(shared Object ownee, shared Object owner)Makes ownee use owner's mutex. This will initialize owner's mutex if it hasn't been set yet. Params: ownee = object to change owner = source objectObject _d_toObject(return scope void * p) @nogc nothrow pure @trustedGiven a pointer: If it is an Object, return that Object. If it is an interface, return the Object implementing the interface. If it is null, return null. Else, undefined crashvoid clear(Value, Key)(Value[Key] aa) @trustedRemoves all remaining keys and values from an associative array. Params: aa = The associative array.Value[Key] rehash(Value, Key)(Value[Key] aa)Reorganizes the associative array in place so that lookups are more efficient. Params: aa = The associative array. Returns: The rehashed associative array. Note: emulated by the compiler during...auto dup(T : V[K], K, V)(T aa)Creates a new associative array of the same size and copies the contents of the associative array into it. Params: aa = The associative array. Note: emulated by the compiler during CTFEauto byKey(T : V[K], K, V)(T aa) pure nothrow @nogc @safeReturns a forward range which will iterate over the keys of the associative array. The keys are returned by reference.auto byValue(T : V[K], K, V)(T aa) pure nothrow @nogc @safeReturns a forward range which will iterate over the values of the associative array. The values are returned by reference.auto byKeyValue(T : V[K], K, V)(T aa) pure nothrow @nogc @safeReturns a forward range which will iterate over the key-value pairs of the associative array. The returned pairs are represented by an opaque type with `.key` and `.value` properties for accessing ...auto keys(Value, Key)(inout Value[Key] aa) @propertyReturns a newly allocated dynamic array containing a copy of the keys from the associative array. Params: aa = The associative array. Returns: A dynamic array containing a copy of the keys. Not...auto values(Value, Key)(inout Value[Key] aa) @propertyReturns a newly allocated dynamic array containing a copy of the values from the associative array. Params: aa = The associative array. Returns: A dynamic array containing a copy of the values....inout(V) get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)If `key` is in `aa`, returns corresponding value; otherwise it evaluates and returns `defaultValue`. Params: aa = The associative array. key = The key. defaultValue = The default value. Retu...V require(K, V)(ref V[K] aa, K key, lazy V value = V.init) refIf `key` is in `aa`, returns corresponding value; otherwise it evaluates `value`, adds it to the associative array and returns it. Params: aa = The associative array. key = The key. value = ...void update(K, V, C, U)(ref V[K] aa, K key, scope C create, scope U update) if (is(typeof(create()) : V) && (is(typeof(update(aa[K.init])) : V) || is(typeof(update(aa[K.init])) == void)))Calls `create` if `key` doesn't exist in the associative array, otherwise calls `update`. `create` returns a corresponding value for `key`. `update` accepts a value parameter. If it returns a value...bool _xopEquals(in void *, in void *)bool _xopCmp(in void *, in void *)size_t getArrayHash(const scope TypeInfo element, const scope void * ptr, const size_t count) @trusted nothrowsize_t capacity(T)(T[] arr) @property pure nothrow @trusted(Property) Gets the current capacity of a slice. The capacity is the size that the slice can grow to before the underlying array must be reallocated or extended.size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trustedReserves capacity for a slice. The capacity is the size that the slice can grow to before the underlying array must be reallocated or extended.inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) ref nothrow @systemAssume that it is safe to append to this array. Appends made to this array after calling this function may append in place, even if the array was a slice of a larger array to begin with.void destroy(bool initialize = true, T)(ref T obj) if (is(T == struct))Destroys the given object and optionally resets to initial state. It's used to destroy an object, calling its destructor or finalizer so it no longer references any other objects. It does not initi...void destroy(bool initialize = true, T)(ref T obj) if (!is(T == struct) && !is(T == interface) && !is(T == class) && !__traits(isStaticArray, T))dittoint __cmp(C1, C2)(C1 lhs, C2 rhs) if ((is(C1 : const(Object)) || (is(C1 == interface) && (__traits(getLinkage, C1) == "D"))) &&
(is(C2 : const(Object)) || (is(C2 == interface) && (__traits(getLinkage, C2) == "D"))))Variables 3
isSafeCopyable = is(typeof(() @safe { union U { T x; } T * x; auto u = U(* x); }))rtinfoNoPointers = nullshortcuts for the precise GC, also generated by the compiler used instead of the actual pointer bitmap
rtinfoHasPointers = cast(void *) 1Templates 4
Create RTInfo for type T
Provides an "inline import", i.e. an import that is only available for a limited lookup. For example:
void fun(imported!"std.stdio".File input)
{
... use File from std.stdio normally ...
}There is no need to import std.stdio at top level, so fun carries its own dependencies. The same approach can be used for template constraints:
void fun(T)(imported!"std.stdio".File input, T value)
if (imported!"std.traits".isIntegral!T)
{
...
}An inline import may be used in conjunction with the with statement as well. Inside the scope controlled by with, all symbols in the imported module are made available:
void fun()
{
with (imported!"std.datetime")
with (imported!"std.stdio")
{
Clock.currTime.writeln;
}
}The advantages of inline imports over top-level uses of the import declaration are the following:
- The
importedtemplate specifies dependencies at declaration level, not atmodule level. This allows reasoning about the dependency cost of declarations in separation instead of aggregated at module level.
- Declarations using
importedare easier to move around because they don'trequire top-level context, making for simpler and quicker refactorings.
- Declarations using
importedscale better with templates. This is becausetemplates that are not instantiated do not have their parameters and constraints instantiated, so additional modules are not imported without necessity. This makes the cost of unused templates negligible. Dependencies are pulled on a need basis depending on the declarations used by client code.
The use of imported also has drawbacks:
- If most declarations in a module need the same imports, then factoring them
at top level, outside the declarations, is simpler than repeating them.
- Traditional dependency-tracking tools such as make and other build systems
assume file-level dependencies and need special tooling (such as rdmd) in order to work efficiently.
- Dependencies at the top of a module are easier to inspect quickly than
dependencies spread throughout the module.
See Also
imported facility. Credit is
due to Daniel Nielsen and Dominikus Dittes Scherkl.