bloomberg/clang-p2996

error: use of undeclared identifier 'expand'

Closed this issue · 2 comments

First of all, thanks for creating this branch!

I am exploring the new reflection capabilities for a json serializer and I am having issues with the following function:

template <typename S>
consteval auto print_struct() {
  constexpr size_t N = []() consteval {
    return nonstatic_data_members_of(^S).size();
  }();
  std::array<field_descriptor, N> member_size;

  [: expand(std::meta::nonstatic_data_members_of(^S)) :] >> [&, i = 0]<auto e>() mutable {
    member_size[i] = {.field_name = name_of(e)};
    ++i;
  };
  return member_size;
};
template<typename S>
consteval auto print_struct() {
    constexpr size_t N = []() consteval {
        return nonstatic_data_members_of(^S).size();
    }();
    std::array<field_descriptor, N> member_size;
    int i = 0;
    template for (constexpr auto e : std::meta::members_of(^S)) {
        member_size[i] = {.field_name = name_of(e)};
        ++i;
    }
    return member_size;
}

I know that this is still an evolving standard, and this might be on the rough edges since it is discussed in the implementation status part (https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2996r1.html#implementation-status)

(https://godbolt.org/z/cMYhd7xc8) -> Version using your branch

(https://godbolt.org/z/TP6fPf1Yn) -> Version using the EDG-reflection, for which the [: expand] workaround works. E

Question: Is this difference of behavior expected (due to the expand work-around implemented by EDG)?

Hey, @FranciscoThiesen ! Thanks for checking out our fork. Hope you don't mind; I've adjusted the name of this issue to make it easier for others to find it who encounter the same implementation divergence.

The difference here is that EDG implements expand in the <experimental/meta> file, whereas we do not (since it's not currently proposed for standardization).

You can see an implementation of it in this example from P2996. Copy-pasta'ing the definition into your godbolt seems to work.

Thanks for clarifying!