aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/non_null_ptr-inl.h
blob: a14b1e93020196478040e03f292f16269a309ae1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#ifndef NON_NULL_PTR_H_
#error "Direct inclusion of this file is not allowed, include helpers.h"
// For the sake of sane code completion.
#include "non_null_ptr.h"
#endif

#include <library/cpp/yt/assert/assert.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

template <class T>
TNonNullPtrBase<T>::TNonNullPtrBase(T* ptr) noexcept
    : Ptr_(ptr)
{
    YT_VERIFY(ptr);
}

template <class T>
T* TNonNullPtrBase<T>::operator->() const noexcept
{
    return Ptr_;
}

template <class T>
T& TNonNullPtrBase<T>::operator*() const noexcept
{
    return *Ptr_;
}

template <class T>
TNonNullPtrBase<T>::TNonNullPtrBase() noexcept
    : Ptr_(nullptr)
{ }

template <class T>
TNonNullPtr<T> GetPtr(T& ref) noexcept
{
    TNonNullPtr<T> ptr;
    ptr.Ptr_ = &ref;

    return ptr;
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT