Skip to content

Commit 96095e3

Browse files
committed
Core (LV::IntrusivePtr): Use concepts to check that element type is reference countable.
1 parent 5ee5d38 commit 96095e3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

libvisual/libvisual/lv_intrusive_ptr.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33

44
namespace LV
55
{
6+
namespace Impl
7+
{
8+
// Checks that the required overloads for LV::IntrusivePtr<> are met.
9+
// NOTE: Only used for concept checking.
10+
template <typename T>
11+
void check_intrusive_ref_countable (T* a)
12+
{
13+
intrusive_ptr_add_ref (a);
14+
intrusive_ptr_release (a);
15+
}
16+
}
17+
18+
//! Concept for reference countable types that can be used with LV::IntrusivePtr.
19+
template <typename T>
20+
concept IntrusiveRefCountable = requires (T* a)
21+
{
22+
Impl::check_intrusive_ref_countable (a);
23+
};
624

725
//! Intrusive smart pointer class template.
826
//!
@@ -15,7 +33,7 @@ namespace LV
1533
//! * void intrusive_ptr_add_ref(T* object) -- _Called to add a reference_
1634
//! * void intrusive_ptr_release(T* object) -- _Called to remove a reference and destroy the object when not longer used_
1735
//!
18-
template <typename T>
36+
template <IntrusiveRefCountable T>
1937
class IntrusivePtr
2038
{
2139
public:

0 commit comments

Comments
 (0)