Код: Выделить всё
INode
Вот очень простой пример:
, который я хотел бы, чтобы это было так: p> p>
, который я хотел бы доступить как as as a triviell as a triviell. />
Код: Выделить всё
rootNode->getA()->getX();
rootNode->getA()->setX(42.0f);
// NOT: rootNode->getA().edit()->setX(42.0f);
Код: Выделить всё
// Transaction wrapper template
// We attempt to have different behaviour, base on if the wrapper->getter()-const or wrapper->setter()
// being getter and setter members of T
template
class TransactionProxy
{
public:
using NonConstT = std::remove_cv_t;
// For const access
const T* operator->() const
{
std::cout () const
{
auto w = TransactionProxy(const_cast(m_obj));
return w;
}
TransactionProxy(T* obj) : m_obj(obj) {}
private:
T* m_obj;
};
...
// Within RootNode
TransactionProxy getA() const
{
return TransactionProxy(m_a.get());
}
Пример 1: Операция только для чтения
const operator-> nalls для 8noderoot
const operator-> Вызов 5nodea
Получение x Значение: 1 < /p>
Пример 2: Запись
const operator-> constrod stor stort stor stort stort stor stort stor stormit stormit stormit a exator
constrom /> Незащитный оператор-> Вызовов для 5nodea
настройка x от 1 до 42
Примечание. Как вы видите, только последний оператор-> () до setx () неконтет и создает Cache Transaction для Node Nodece . /> Можно ли реализовать что -то подобное без рефлексии TS? Как? < /Strong> < /p>
called for " ()
{
std::cout
Подробнее здесь: https://stackoverflow.com/questions/795 ... ition-in-c