]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/TypeTraits.h
Source Format Enforcement (#963)
[thirdparty/squid.git] / src / base / TypeTraits.h
1 /*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_SRC_BASE_TYPETRAITS_H
10 #define SQUID_SRC_BASE_TYPETRAITS_H
11
12 namespace TypeTraits_ { // a hack to prevent "unintended ADL"
13
14 // TODO: Extract reusable paradigms into other mixins (e.g., NonCopyable).
15 /// convenience base for any class with pure virtual method(s)
16 class Interface
17 {
18 public:
19 // ensures proper destruction via pointers to base interface classes
20 virtual ~Interface() = default;
21
22 // prohibits copy/move assignment to prevent accidental object slicing
23 Interface &operator=(const Interface &) = delete;
24 Interface &operator=(Interface &&) = delete;
25
26 protected: // prevents accidental creation of Interface instances
27
28 // allows default-construction in kids
29 constexpr Interface() = default;
30
31 // allows copy/move construction for kids convenience
32 Interface(const Interface &) = default;
33 Interface(Interface &&) = default;
34 };
35
36 } // namespace TypeTraits_
37
38 using Interface = TypeTraits_::Interface;
39
40 #endif /* SQUID_SRC_BASE_TYPETRAITS_H */
41