www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21192] New: std.traits: Add trait for determining if a type


          Issue ID: 21192
           Summary: std.traits: Add trait for determining if a type has
                    padding/alignment holes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

Created attachment 1802
  --> https://issues.dlang.org/attachment.cgi?id=1802&action=edit
example implementation

Such a trait could be used by core.internal.convert.toUbyte() to determine
whether it is safe to return all bits of a struct to compute the hash, or does
it need to selectively copy all fields.

Rationale: structs that are passed around in registers typically discard any
memset() operation done to zero all alignment holes, so comparing all bits for
equality may not work.

Attached example implementation.

Aug 23 2020