Skip to content

specify Unsigned, Integral, Floating, Arithmetic and Scalar Types #2546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions spec/traits.dd
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ $(GNAME TraitsArgument):

$(H2 $(GNAME isArithmetic))

$(P If the arguments are all either types that are arithmetic types,
or expressions that are typed as arithmetic types, then $(D true)
$(P If the arguments are all either types that are $(DDSUBLINK type, Arithmetic Type, $(I Arithmetic Type)), or
expressions that are typed as arithmetic types, then $(D true)
is returned.
Otherwise, $(D false) is returned.
If there are no arguments, $(D false) is returned.)
Expand Down Expand Up @@ -111,8 +111,7 @@ false

$(H2 $(GNAME isFloating))

$(P Works like $(D isArithmetic), except it's for floating
point types (including imaginary and complex types).)
$(P Works like $(GLINK isArithmetic), except it's for $(DDSUBLINK type, Floating Type, $(I Floating Type)).)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
Expand All @@ -132,8 +131,7 @@ static assert(!__traits(isFloating, float[4]));

$(H2 $(GNAME isIntegral))

$(P Works like $(D isArithmetic), except it's for integral
types (including character types).)
$(P Works like $(GLINK isArithmetic), except it's for $(DDSUBLINK type, Integral Type, $(I Integral Type)).)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
Expand All @@ -155,8 +153,7 @@ static assert(!__traits(isIntegral, void*));

$(H2 $(GNAME isScalar))

$(P Works like $(D isArithmetic), except it's for scalar
types.)
$(P Works like $(GLINK isArithmetic), except it's for $(DDSUBLINK type, Scalar Type, $(I Scalar Type)).)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
Expand All @@ -182,8 +179,7 @@ static assert(!__traits(isScalar, Object));

$(H2 $(GNAME isUnsigned))

$(P Works like $(D isArithmetic), except it's for unsigned
types.)
$(P Works like $(GLINK isArithmetic), except it's for $(DDSUBLINK type, Unsigned Type, $(I Unsigned Type)).)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
Expand All @@ -208,7 +204,7 @@ static assert(!__traits(isUnsigned, void*));

$(H2 $(GNAME isStaticArray))

$(P Works like $(D isArithmetic), except it's for static array
$(P Works like $(GLINK isArithmetic), except it's for static array
types.)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
Expand All @@ -228,7 +224,7 @@ static assert(!__traits(isStaticArray, array));

$(H2 $(GNAME isAssociativeArray))

$(P Works like $(D isArithmetic), except it's for associative array
$(P Works like $(GLINK isArithmetic), except it's for associative array
types.)

$(H2 $(GNAME isAbstractClass))
Expand Down Expand Up @@ -810,7 +806,6 @@ $(CONSOLE
tuple("pure", "nothrow", "@nogc", "@trusted")
)
)
)

$(H2 $(GNAME getLinkage))

Expand Down
71 changes: 69 additions & 2 deletions spec/type.dd
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ $(H2 $(LEGACY_LNAME2 Derived Data Types, derived-data-types, Derived Data Types)

$(UL
$(LI pointer)
$(LI array)
$(LI static array)
$(LI dynamic array)
$(LI associative array)
$(LI function)
$(LI delegate)
$(LI vector)
)

$(P $(DDSUBLINK spec/arrays, strings, $(I Strings)) are a special case of arrays.)
Expand All @@ -62,7 +64,7 @@ $(H2 $(LEGACY_LNAME2 User Defined Types, user-defined-types, User-Defined Types)
$(LI struct)
$(LI union)
$(LI class)

$(LI interface)
)

$(H2 $(LEGACY_LNAME2 Base Types, base-types, Base Types))
Expand All @@ -73,6 +75,71 @@ $(H2 $(LEGACY_LNAME2 Base Types, base-types, Base Types))
enum E : T { ... } // T is the base type of E
---

$(H2 $(LNAME2 Unsigned Type, Unsigned Type))

$(P The following are $(I Unsigned Type):)

$(UL
$(LI bool)
$(LI ubyte) $(LI ushort) $(LI uint) $(LI ulong) $(LI ucent)
$(LI char) $(LI wchar) $(LI dchar)
)

$(P If the $(GLINK2 enum, EnumBaseType) of an enum is an $(I Unsigned Type), the enum
is an $(I Unsigned Type).)

$(P If the element type of a vector is an $(I Unsigned Type), the vector
is an $(I Unsigned Type).)

$(H2 $(LNAME2 Integral Type, Integral Type))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say "Integral Type, Signed Type"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integral includes signed and unsigned types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused when one section said "Unsigned Type" and one said "Integral Type".


$(P The following are $(I Integral Type):)

$(UL
$(LI $(DDSUBLINK type, Unsigned Type, $(I Unsigned Type)))
$(LI byte) $(LI short) $(LI int) $(LI long) $(LI cent)
)

$(P If the $(GLINK2 enum, EnumBaseType) of an enum is an $(I Integral Type), the enum
is an $(I Integral Type).)

$(P If the element type of a vector is an $(I Integral Type), the vector
is an $(I Integral Type).)

$(H2 $(LNAME2 Floating Type, Floating Type))

$(P The following are $(I Floating Type):)

$(UL
$(LI float) $(LI double) $(LI real)
$(LI ifloat) $(LI idouble) $(LI ireal)
$(LI cfloat) $(LI cdouble) $(LI creal)
)

$(P If the $(GLINK2 enum, EnumBaseType) of an enum is a $(I Floating Type), the enum
is a $(I Floating Type).)

$(P If the element type of a vector is a $(I Floating Type), the vector
is a $(I Floating Type).)

$(H2 $(LNAME2 Arithmetic Type, Arithmetic Type))

$(P The following are $(I Arithmetic Type):)

$(UL
$(LI $(DDSUBLINK type, Integral Type, $(I Integral Type)))
$(LI $(DDSUBLINK type, Floating Type, $(I Floating Type)))
)

$(H2 $(LNAME2 Scalar Type, Scalar Type))

$(P The following are $(I Scalar Type):)

$(UL
$(LI $(DDSUBLINK type, Arithmetic Type, $(I Arithmetic Type)))
$(LI $(I Pointer))
)

$(H2 $(LEGACY_LNAME2 Pointer Conversions, pointer-conversions, Pointer Conversions))

$(P Casting pointers to non-pointers and vice versa is allowed.)
Expand Down