Skip to content

[HLSL 2021] Setter array subscript operator overload #4341

Open

Description

@tomjohnstone

Hi,

How can I implement a setter array subscript operator overload? A getter works like this but doesn't require references like C does.

Thanks,
Tom

struct MyArray {
  float4 A[MAX_SIZE];
  
  float4 operator[](int ix) {
    if (ix >= MAX_SIZE)
      return 0.0;
    return A[ix];
  };
};

Activity

  1. natevm commented on Oct 8, 2022

    @natevm
    Contributor

    Running into the same issue about a year later. How can we assign to the subscript operator?

  2. pow2clk commented on Nov 28, 2022

    @pow2clk
    Collaborator

    Unfortunately, this is not currently possible due to lack of reference support in HLSL. It is something we want to improve in later versions.

  3. added
    hlsl-next
    on Jun 30, 2023
  4. llvm-beanz commented on Jun 30, 2023

    @llvm-beanz
    Collaborator

    This is caused by broken behavior in DXC's overload resolution. We have a bunch of related issues that will need to be addressed in order to support this planned fix for HLSL 202x.

    That feature is effectively going to result in us adopting C++ overload rules completely for HLSL, which should solve this and related issues.

  5. added
    hlsl2021
    on Jun 30, 2023
  6. removed
    hlsl2021
    on Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hlsl-next

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions