MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Badge.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14namespace Mcro::Badge
15{
16 /**
17 * Use this template to give exclusive access to functions to specific classes, like so:
18 * class A;
19 * class B;
20 * class C;
21 *
22 * class A
23 * {
24 * static void CallFromB(TBadge<B> badge) {...}
25 * };
26 *
27 * class B
28 * {
29 * void Foobar()
30 * {
31 * // OK
32 * A::CallFromB({});
33 * }
34 * };
35 *
36 * class C
37 * {
38 * void Foobar()
39 * {
40 * // compile error:
41 * // badge template instance declared in A::CallFromB is only friends with class B,
42 * // therefore the private default constructor is inaccessible from class C
43 * A::CallFromB({});
44 * }
45 * };
46 */
47 template<class T>
48 class TBadge
49 {
50 friend T;
51 private: TBadge() {}
52 };
53}
54
55template <typename T>