MCRO
C++23 utilities for Unreal Engine.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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 * @brief
18 * Use this template to give exclusive access to functions to specific classes.
19 *
20 * Like so:
21 * @code
22 * class A;
23 * class B;
24 * class C;
25 *
26 * class A
27 * {
28 * static void CallFromB(TBadge<B> badge) {...}
29 * };
30 *
31 * class B
32 * {
33 * void Foobar()
34 * {
35 * // OK
36 * A::CallFromB({});
37 * }
38 * };
39 *
40 * class C
41 * {
42 * void Foobar()
43 * {
44 * // compile error:
45 * // badge template instance declared in A::CallFromB is only friends with class B,
46 * // therefore the private default constructor is inaccessible from class C
47 * A::CallFromB({});
48 * }
49 * };
50 * @endcode
51 */
52 template<class T>
53 class TBadge
54 {
55 friend T;
56 private: TBadge() {}
57 };
58}
Use this template to give exclusive access to functions to specific classes.
Definition Badge.h:54