Skip to content

Instantly share code, notes, and snippets.

@Frityet
Last active August 9, 2022 01:02
Show Gist options
  • Save Frityet/d5d38077aeeba31e13dfc4b7eef92002 to your computer and use it in GitHub Desktop.
Save Frityet/d5d38077aeeba31e13dfc4b7eef92002 to your computer and use it in GitHub Desktop.
#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