NonCopyableAnalyzer icon indicating copy to clipboard operation
NonCopyableAnalyzer copied to clipboard

move semantics

Open ufcpp opened this issue 7 years ago • 0 comments

interface INonCopyable { }

interface IMovable : INonCopyable
{
    // void OnMoved(); ?
}

static class MoveExtensions
{
    public static T Move<T>(ref this T x)
        where T : struct, IMovable
    {
        // needs interlocked exchange?
        var t = x;
        // x.OnMoved(); ?
        x = default;
        return t;
    }
}
  • allow var y = x.Move();
  • disallow to use x after Move

This is not so hard for local variables and parameters but fields.

ufcpp avatar Dec 15 '17 15:12 ufcpp