HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_CallIf.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_TypeTraits.h (SYS Library, C++)
7  *
8  * COMMENTS: Wrapper for Boost.TypeTraits
9  */
10 
11 #ifndef __SYS_CALLIF_H_INCLUDED__
12 #define __SYS_CALLIF_H_INCLUDED__
13 
14 /// @file
15 
16 #include "SYS_Compiler.h"
17 #include "SYS_Deprecated.h"
18 #include "SYS_Inline.h"
19 
20 #include <utility>
21 
22 #if SYS_HAS_CXX14
23  #define SYS_CALLIF_AUTO auto
24 #else
25  #define SYS_CALLIF_AUTO
26 #endif
27 
28 #if defined(__clang__) || !defined(_MSC_VER) || _MSC_VER >= 1930
29  #define SYS_CALLIF_DEPRECATED SYS_DEPRECATED_REPLACE(20.0, "if constexpr")
30 #else
31  #define SYS_CALLIF_DEPRECATED
32 #endif
33 
34 /// This is replaced by 'if constexpr' in C++17.
35 ///
36 /// This function is for use with lambdas to force the compiler to
37 /// not even try compiling or inlining function calls when a compile-time
38 /// condition is false.
39 ///
40 /// Usage: SYS_CallIf<CONDITION>::call([&](SYS_CALLIF_AUTO) { ... });
41 ///
42 /// @note Your lambda must have exactly 1 parameter of type SYS_CALLIF_AUTO
43 /// @{
44 template<bool CONDITION>
45 struct SYS_CallIf
46 {
47  template<typename FUNCTOR, typename... ARGS>
49  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
50  {
51  // No call at all if CONDITION is false
52  }
53 };
54 
55 template<>
56 struct SYS_CallIf<true>
57 {
58 #if SYS_HAS_CXX14
59  template<typename FUNCTOR, typename... ARGS>
61  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
62  {
63  struct dummy {};
64  functor(dummy(), std::forward<ARGS>(args)...);
65  }
66 #else
67  template<typename FUNCTOR, typename... ARGS>
69  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
70  {
71  functor(std::forward<ARGS>(args)...);
72  }
73 #endif
74 };
75 /// @}
76 
77 #endif // __SYS_CALLIF_H_INCLUDED__
static SYS_CALLIF_DEPRECATED SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS &&...args)
Definition: SYS_CallIf.h:49
static SYS_CALLIF_DEPRECATED SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS &&...args)
Definition: SYS_CallIf.h:69
#define SYS_CALLIF_DEPRECATED
Definition: SYS_CallIf.h:29
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
constexpr enabler dummy
An instance to use in EnableIf.
Definition: CLI11.h:985
**If you just want to fire and args
Definition: thread.h:609