Is there a way to constrain generic placeholder has to be value type?

The concept of value semantics is a tricky one. There have been some legendary discussions about it here on the forums, for example ValueSemantic protocol.

When thinking about this I try to keep in mind:

  • NSUUID, which is an reference type, but is always immutable [1] and thus has value semantics.

  • File descriptors, commonly modelled as CInt, which are value types but do have reference semantics.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] Well, if you ignore subclasses, but subclassing NSUUID would be bananas.

5 Likes