aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/noncopyable.h
blob: 655436a70dba3e44d6d415f121aad74256e09af3 (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
#pragma once

/** 
 * @class TNonCopyable 
 *
 * Inherit your class from `TNonCopyable` if you want to make it noncopyable. 
 *
 * Example usage: 
 * @code 
 * class Foo: private TNonCopyable { 
 *     // ... 
 * }; 
 * @endcode 
 */

namespace NNonCopyable { // protection from unintended ADL
    struct TNonCopyable { 
        TNonCopyable(const TNonCopyable&) = delete;
        TNonCopyable& operator=(const TNonCopyable&) = delete;

        TNonCopyable() = default;
        ~TNonCopyable() = default;
    };

    struct TMoveOnly { 
        TMoveOnly(TMoveOnly&&) noexcept = default;
        TMoveOnly& operator=(TMoveOnly&&) noexcept = default;

        TMoveOnly(const TMoveOnly&) = delete;
        TMoveOnly& operator=(const TMoveOnly&) = delete;

        TMoveOnly() = default;
        ~TMoveOnly() = default;
    };
}

using TNonCopyable = NNonCopyable::TNonCopyable;
using TMoveOnly = NNonCopyable::TMoveOnly;