1 | /** @file
|
---|
2 | * innotek Portable Runtime - C++ Utilities (useful templates, defines and such).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___iprt_cpputils_h
|
---|
18 | #define ___iprt_cpputils_h
|
---|
19 |
|
---|
20 | /** @defgroup grp_rt_cpputils C++ Utilities
|
---|
21 | * @ingroup grp_rt
|
---|
22 | * @{
|
---|
23 | */
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Shortcut to |const_cast<C &>()| that automatically derives the correct
|
---|
27 | * type (class) for the const_cast template's argument from its own argument.
|
---|
28 | * Can be used to temporarily cancel the |const| modifier on the left-hand side
|
---|
29 | * of assignment expressions, like this:
|
---|
30 | * @code
|
---|
31 | * const Class that;
|
---|
32 | * ...
|
---|
33 | * unconst (that) = some_value;
|
---|
34 | * @endcode
|
---|
35 | */
|
---|
36 | template <class C>
|
---|
37 | inline C &unconst (const C &that) { return const_cast <C &> (that); }
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Shortcut to |const_cast<C *>()| that automatically derives the correct
|
---|
42 | * type (class) for the const_cast template's argument from its own argument.
|
---|
43 | * Can be used to temporarily cancel the |const| modifier on the left-hand side
|
---|
44 | * of assignment expressions, like this:
|
---|
45 | * @code
|
---|
46 | * const Class *that;
|
---|
47 | * ...
|
---|
48 | * unconst (that) = some_value;
|
---|
49 | * @endcode
|
---|
50 | */
|
---|
51 | template <class C>
|
---|
52 | inline C *unconst (const C *that) { return const_cast <C *> (that); }
|
---|
53 |
|
---|
54 | /** @} */
|
---|
55 |
|
---|
56 | #endif
|
---|
57 |
|
---|