NeverFreedPointer implementation improved and fixed for MSVC.

This commit is contained in:
John Preston 2016-04-07 20:16:02 +04:00
parent a37bbcfaca
commit a56ece4efe
3 changed files with 9 additions and 9 deletions

View File

@ -824,6 +824,13 @@ public:
}
}
template <typename... Args>
void makeIfNull(Args&&... args) {
if (isNull()) {
reset(new T(std::forward<Args>(args)...));
}
};
T *data() const {
return _p;
}
@ -857,13 +864,6 @@ private:
};
template <typename T>
using NeverFreedPointerCreator = T*(*)();
template <typename T, typename... Args>
inline NeverFreedPointerCreator<T> MakeNeverFreedCreator(Args&&... args) {
return [&args...]() -> T* { return new T(std_::forward<Args>(args)...); };
}
// This pointer is used for static non-POD variables that are allocated
// on first use by constructor and are never automatically freed.
template <typename T>

View File

@ -86,7 +86,7 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) {
}
}
if (p) {
_active.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
_active.makeIfNull();
*_active = p;
if ((_activeHost = host)) {
bool emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);

View File

@ -366,7 +366,7 @@ public:
if (!_active || !*_active) {
return;
}
_pressed.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
_pressed.makeIfNull();
*_pressed = *_active;
if ((_pressedHost = _activeHost)) {
_pressedHost->clickHandlerPressedChanged(*_pressed, true);