#define DALI_INTRUSIVE_PTR_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
+// EXTERNAL INCLUDES
+#include <cstddef> // for std::nullptr_t
+
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
IntrusivePtr(rhs).Swap(*this);
}
- // IntrusivePtr comparisons - This is a variation of the safe bool idiom
-
- /**
- * @brief Pointer-to-member type.
- *
- * Objects can be implicitly converted to this for validity checks.
- */
- using BooleanType = void (IntrusivePtr<T>::*)() const;
+ // IntrusivePtr comparisons
/**
- * @brief Converts an object handle to a BooleanType.
+ * @brief Converts an object handle to a bool.
*
* This is useful for checking whether the handle is NULL.
* @SINCE_1_0.0
*/
- operator BooleanType() const
+ explicit operator bool() const
{
- return mPtr ? &IntrusivePtr::ThisIsSaferThanReturningVoidStar : nullptr;
+ return mPtr != nullptr;
}
/**
private:
/**
- * @brief Used by the safe bool idiom.
- * @SINCE_1_0.0
- */
- void ThisIsSaferThanReturningVoidStar() const
- {
- }
-
- /**
* @brief Internal swap function.
* @SINCE_1_0.0
*/
}
/**
+ * @brief Comparison overrides of objects with nullptr_t.
+ *
+ * @SINCE_2_1.12
+ * @param[in] lhs Intrusive pointer to compare with
+ * @param[in] rhs nullptr
+ * @return True if the pointers is nullptr
+ */
+template<typename T>
+inline bool operator==(IntrusivePtr<T> const& lhs, std::nullptr_t rhs)
+{
+ return lhs.Get() == nullptr;
+}
+
+/**
+ * @brief Comparison overrides of objects with nullptr_t.
+ *
+ * @SINCE_2_1.12
+ * @param[in] lhs Intrusive pointer to compare with
+ * @param[in] rhs nullptr
+ * @return True if the pointers is not nullptr
+ */
+template<typename T>
+inline bool operator!=(IntrusivePtr<T> const& lhs, std::nullptr_t rhs)
+{
+ return lhs.Get() != nullptr;
+}
+
+/**
+ * @brief Comparison overrides of objects with nullptr_t.
+ *
+ * @SINCE_2_1.12
+ * @param[in] lhs nullptr
+ * @param[in] rhs Intrusive pointer to compare against
+ * @return True if the pointers is nullptr
+ */
+template<typename T>
+inline bool operator==(std::nullptr_t lhs, IntrusivePtr<T> const& rhs)
+{
+ return nullptr == rhs.Get();
+}
+
+/**
+ * @brief Comparison overrides of objects with nullptr_t.
+ *
+ * @SINCE_2_1.12
+ * @param[in] lhs nullptr
+ * @param[in] rhs Intrusive pointer to compare against
+ * @return True if the pointers is not nullptr
+ */
+template<typename T>
+inline bool operator!=(std::nullptr_t lhs, IntrusivePtr<T> const& rhs)
+{
+ return nullptr != rhs.Get();
+}
+
+/**
* @}
*/
} // namespace Dali