Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created June 21, 2023 07:07
Show Gist options
  • Save guitarrapc/173b9bb030c608f1f341e61b199b7374 to your computer and use it in GitHub Desktop.
Save guitarrapc/173b9bb030c608f1f341e61b199b7374 to your computer and use it in GitHub Desktop.
C# bool is not Blittable. Instead, use byte or wrap byte to offer BlittableBool.
public struct BlittableBool
{
public readonly byte Value;
public BlittableBool(byte value)
{
Value = value;
}
public BlittableBool(bool value)
{
Value = value ? (byte)1 : (byte)0;
}
public static implicit operator bool(BlittableBool bb)
{
return bb.Value != 0;
}
public static implicit operator BlittableBool(bool b)
{
return new BlittableBool(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment