计算属性自动检查
This commit is contained in:
@@ -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">();
|
||||
}
|
||||
Reference in New Issue
Block a user