plugify
1.0.0.0
Loading...
Searching...
No Matches
include
plugify
reference_wrapper.hpp
1
#pragma once
2
3
#include <type_traits>
4
#include <utility>
5
6
namespace
plugify {
17
template
<
typename
T>
18
class
Ref
{
19
public
:
20
Ref
() noexcept : _impl{
nullptr
} {}
21
Ref
(T& impl) noexcept : _impl{std::addressof(impl)} {}
22
23
Ref
(
Ref
const
&) =
default
;
24
Ref
(
Ref
&&) =
default
;
25
26
bool
operator==(
const
Ref
& other)
const
noexcept
{
return
_impl == other._impl; }
27
bool
operator==(
const
T* impl)
const
noexcept
{
return
_impl == impl; }
28
29
Ref
& operator=(
const
Ref
&) & =
default
;
30
Ref
& operator=(
const
Ref
&) && =
delete
;
31
Ref
& operator=(
Ref
&&) & =
default
;
32
Ref
& operator=(
Ref
&&) && =
delete
;
33
34
explicit
operator
bool()
const
noexcept
{
35
return
_impl !=
nullptr
;
36
}
37
38
const
void
*
const
GetPtr()
const
noexcept
{
39
return
_impl;
40
}
41
42
protected
:
43
T* _impl;
44
};
45
55
template
<
typename
T>
static
constexpr
bool
is_ref_v = std::is_standard_layout_v<T> &&
sizeof
(T) ==
sizeof
(
void
*);
56
}
57
58
// Specialize std::hash for Ref<T>
59
template
<
typename
T>
60
struct
std::hash<plugify::Ref<T>> {
61
std::size_t operator()(
const
plugify::Ref<T>
& ref)
const
{
62
return
std::hash<void*>{}(ref.GetPtr());
63
}
64
};
plugify::Ref
A lightweight reference wrapper for objects of type T.
Definition
reference_wrapper.hpp:18
Generated by
1.9.8