计算属性自动检查

This commit is contained in:
2026-08-11 11:54:09 +08:00
parent 11407faf86
commit e91f134f16
14 changed files with 305 additions and 51 deletions
@@ -0,0 +1,21 @@
#include <structive/property/property.hpp>
using namespace structive;
struct Device : Property_Object<Device> {
int value{};
int hidden{};
};
template <>
struct structive::Type_Descriptor<Device> {
static auto get() {
return object<Device>(
field<&Device::value>(key<"value">),
computed_property<Device, int>(depends_on<&Device::hidden>, [](const auto& view) {
return view.template get<&Device::hidden>();
}, key<"computed">)
);
}
};
int main() {
static_cast<void>(Type_Descriptor<Device>::get());
return 0;
}
@@ -0,0 +1,23 @@
#include <structive/property/property.hpp>
using namespace structive;
struct Device : Property_Object<Device> {
int left{};
int right{};
};
template <>
struct structive::Type_Descriptor<Device> {
static auto get() {
return object<Device>(
synchronization(sync_all_shared),
field<&Device::left>(key<"left">),
field<&Device::right>(key<"right">),
computed_property<Device, int>(depends_on<&Device::left>, [](const auto& view) {
return view.template get<&Device::right>();
}, key<"computed">)
);
}
};
int main() {
Device device;
return device.read<"computed">();
}