brevzin / cpp_proposals

My WG21 proposals
33 stars 22 forks source link

Improve wording of intro and spec API of P3294 #172

Open bernhardmgruber opened 1 month ago

bernhardmgruber commented 1 month ago

Hi! @andralex asked me to review is paper, but I only had time to read the Spec API section. Here are some wording improvements and feedback:

struct Book { consteval { property<^Book>("author", ^std::string); // !!! pass reflection to containing class property<^Book>("title", ^std::string); } };

which allows:
```c++
template <std::meta::info Class>
consteval auto property(string_view name, meta::info type) -> void {
    constexpr auto member = inject(data_member_spec{ // !!! inject() is consteval
        .name=std::format("m_{}", name),
        .type=type
    });

    inject(function_member_spec{
        .name=std::format("get_{}", name),
        .body=^[]([:Class:] const& self) -> auto const& { // !!! splice Class
            return self.[:member:];
        }
    });

    // setter
}

Which seems to provide a solution to the question. It's still cumbersome to pass in the scope to inject into. But if std::meta::current() were consteval as well (which it should), we could just do:

    inject(function_member_spec{
        .name=std::format("get_{}", name),
        .body=^[]([:std::meta::current():] const& self) -> auto const& {
            return self.[:member:];
        }
    });