VirtualBox

source: vbox/trunk/include/iprt/cpp/meta.h@ 78286

Last change on this file since 78286 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/** @file
2 * IPRT - C++ Meta programming.
3 */
4
5/*
6 * Copyright (C) 2011-2019 Oracle Corporation
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 (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_cpp_meta_h
27#define IPRT_INCLUDED_cpp_meta_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/types.h>
33
34/** @defgroup grp_rt_cpp_meta C++ Meta programming utilities
35 * @ingroup grp_rt_cpp
36 * @{
37 */
38
39/**
40 * Check for a condition on compile time and dependent of the result TrueResult
41 * or FalseResult will be defined.
42 *
43 * @param Condition Condition to check.
44 * @param TrueResult Result when condition is true.
45 * @param FalseResult Result when condition is false
46 */
47template <bool Condition, typename TrueResult, typename FalseResult>
48struct RTCIf;
49
50/**
51 * Check for a condition on compile time and dependent of the result TrueResult
52 * or FalseResult will be defined.
53 *
54 * True specialization of RTCIf.
55 *
56 * @param TrueResult Result when condition is true.
57 * @param FalseResult Result when condition is false
58 */
59template <typename TrueResult, typename FalseResult>
60struct RTCIf<true, TrueResult, FalseResult>
61{
62 typedef TrueResult result;
63};
64
65/**
66 * Check for a condition on compile time and dependent of the result TrueResult
67 * or FalseResult will be defined.
68 *
69 * False specialization of RTCIf.
70 *
71 * @param TrueResult Result when condition is true.
72 * @param FalseResult Result when condition is false
73 */
74template <typename TrueResult, typename FalseResult>
75struct RTCIf<false, TrueResult, FalseResult>
76{
77 typedef FalseResult result;
78};
79
80/**
81 * Check if @a T is a pointer or not at compile time and dependent of the
82 * result TrueResult or FalseResult will be defined.
83 *
84 * False version of RTCIfPtr.
85 *
86 * @param Condition Condition to check.
87 * @param TrueResult Result when condition is true.
88 * @param FalseResult Result when condition is false
89 */
90template <class T, typename TrueResult, typename FalseResult>
91struct RTCIfPtr
92{
93 typedef FalseResult result;
94};
95
96/**
97 * Check if @a T is a pointer or not at compile time and dependent of the
98 * result TrueResult or FalseResult will be defined.
99 *
100 * True specialization of RTCIfPtr.
101 *
102 * @param Condition Condition to check.
103 * @param TrueResult Result when condition is true.
104 * @param FalseResult Result when condition is false
105 */
106template <class T, typename TrueResult, typename FalseResult>
107struct RTCIfPtr<T*, TrueResult, FalseResult>
108{
109 typedef TrueResult result;
110};
111
112/** @} */
113
114#endif /* !IPRT_INCLUDED_cpp_meta_h */
115
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette