bloomberg / clang-p2996

Experimental clang support for WG21 P2996 (Reflection).
https://github.com/bloomberg/clang-p2996/tree/p2996/P2996.md
51 stars 8 forks source link

Implement `is_structured_binding` metafunction #58

Closed BaLiKfromUA closed 2 months ago

BaLiKfromUA commented 2 months ago

Implements #44

Describe your changes

Added implementation of is_structured_binding + adapted implementation of type_of and extract functions

Testing performed

Added tests for my changes to entity-classification.pass.cpp

 env LIT_FILTER=entity-classification.pass.cpp ninja check-cxx -C build-llvm/
....
Testing Time: 1.17s

Total Discovered Tests: 9692
  Excluded: 9691 (99.99%)
  Passed  :    1 (0.01%)
BaLiKfromUA commented 2 months ago

I created this PR to receive feedback about my current progress while I am dealing with new implementation of #11 .

I tried to cover 3 main cases mentioned in the issue but will come back and add more tests later.

Plus, need to investigate needs for changes of related functions -- type_of, extract

BaLiKfromUA commented 2 months ago

Thanks for the initial review! I will work on testing and adapting type_of and extract implementations.

So far, at least type_of implementation is definetely needs few small changes.

After my test&fixes, I'll request your review again + meanwhile will investigate which implemented functions might need some changes

BaLiKfromUA commented 2 months ago

I think I am ready for next iteration of review. I slightly changed implementations of type_of and extract functions.

One remark about my changes: I am not sure about my changes to extract function because I didn't come up with all relevant test cases. My current tests are inspired by tests from to-and-from-values.pass.cpp.

constexpr auto p = std::pair{1, 2};
auto& [x4, y4] = p;

static_assert(extract<int>(^x4) == x4);
static_assert(extract<int&>(^x4) == x4);
static_assert(&extract<int&>(^x4) == &x4);

static_assert(extract<int>(^y4) == y4);
static_assert(extract<int&>(^y4) == y4);
static_assert(&extract<int&>(^y4) == &y4);
katzdm commented 2 months ago

I think I am ready for next iteration of review. I slightly changed implementations of type_of and extract functions.

One remark about my changes: I am not sure about my changes to extract function because I didn't come up with all relevant test cases. My current tests are inspired by tests from to-and-from-values.pass.cpp.

constexpr auto p = std::pair{1, 2};
auto& [x4, y4] = p;

static_assert(extract<int>(^x4) == x4);
static_assert(extract<int&>(^x4) == x4);
static_assert(&extract<int&>(^x4) == &x4);

static_assert(extract<int>(^y4) == y4);
static_assert(extract<int&>(^y4) == y4);
static_assert(&extract<int&>(^y4) == &y4);

Valentyn, I think these look great! Note that it hasn't been decided yet whether to support extract or type_of on structured bindings for P2996 (though the current wording for type_of seems like it would support it). Let's keep this for now though. Your changes will be on public godbolt tomorrow, so please feel free to poke and prod the APIs; let me know if anything looks wrong or crashes.

Thanks so much for the contribution!!