Last active
August 9, 2022 01:02
-
-
Save Frityet/d5d38077aeeba31e13dfc4b7eef92002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
namespace XTD | |
{ | |
template<typename T> | |
using Get_f = T (*)(const T *); | |
template<typename T> | |
using Set_f = T &(*)(T *, const T &); | |
template<typename T> | |
struct Property { | |
public: | |
using Get_f = Get_f<T>; | |
using Set_f = Set_f<T>; | |
T value; | |
Get_f get = [](const T *val) -> T { return *val; }; | |
Set_f set = [](T *val, const T &val2) -> T &{ return *val = val2; }; | |
constexpr Property(const Property &) = delete; | |
constexpr Property(Property &&) = delete; | |
constexpr T getv() const noexcept { return get(&value); } | |
constexpr T &setv(const T &val) noexcept { return set(&value, val); } | |
constexpr operator T() const noexcept { return getv(); } | |
constexpr T &operator=(const T &val) noexcept { return setv(val); } | |
}; | |
template<typename T> | |
using property = struct Property<T>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment