D Language in Properties

xiaoxiao2021-03-06  43

Properties

Each type and expression have properties that can be queried:

Int.sizeof / / 4

Float.na // Get floating point NAN (Not a Number) value

(float) .NAN // NAN value of floating point number

(3) .SizeOf // 4 (because 3 is int)

2.SizeOf // syntax error, because "2." is a floating point number

INT.INIT // INT type initial value

Integer data type, other properties

.init initial value (0)

.sizeof size in bytes (equivalent to C's sizeof (Type))

.alignof is aligned

.max maximum

.min minimum

Floating point other attribute

Initial value (NAN)

.sizeof size in bytes (equivalent to C's sizeof (Type))

.alignof is aligned

Infinite .infinity

.nan nan value

.dig converts the accuracy of the decimal representation

.epsilon minimum increasing value

.MANT_DIG number of digits (bit)

.max_10_exp The maximum level of the base

.max_exp The maximum degree of 2 is 2

.min_10_exp The minimum class of 10 is the base

.min_exp The minimum class of 2 is the base

.max can represent the maximum value (except for infinity)

.min can be represented by the minimum (except 0)

.init attribute

.init produces a constant expression that is the default initial value. If applied to a type, its value is the default initial value of this type. If applied to a variable or domain, its value is this variable or the default initial value of the domain. E.g:

Int a;

INT b = 1;

Typedef Int t = 2;

T c;

T D = CAST (T) 3;

INT.INIT // IS 0

a.init // is 0

B.init // is 1

T.init // IS 2

C.init // is 2

D.init // IS 3

Struct foo

{

Int a;

INT b = 7;

}

FOO.a.init // is 0

FOO.B.INIT / / IS 7

Class and structure properties

The attribute is a member function, but it is seen as a domain in syntax. Attribute readable writable. You can read the properties by calling a parameterless method. By calling a method with a parameter, the attribute assigns, the parameter represents the new value of the attribute.

Simple properties can be:

Struct foo

{

INT data () {return m_data;} // read attribute

INT DATA (INT Value) {Return M_Data = Value;} // Write Properties

Private:

INT M_DATA;

}

usage:

Int test ()

{

Foo f;

f.data = 3; // Is equivalent to F.DATA (3);

Return F.Data 3; // Equivalent to returnif.data () 3;

}

If there is no reading method, it means that attribute is read-only. You can have multiple write methods coexisting, which function is used to use the normal overload rule.

In other aspects, these methods are the same as other methods. They can be static, have different linkages, overloaded, take address, and more.

Note: The current attribute cannot be the left value of the OP =, or - operator.

转载请注明原文地址:https://www.9cbs.com/read-59403.html

New Post(0)