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_Inline.h"
18 
19 #include <utility>
20 
21 #if SYS_HAS_CXX14
22  #define SYS_CALLIF_AUTO auto
23 #else
24  #define SYS_CALLIF_AUTO
25 #endif
26 
27 /// This function is for use with lambdas to force the compiler to
28 /// not even try compiling or inlining function calls when a compile-time
29 /// condition is false.
30 ///
31 /// Usage: SYS_CallIf<CONDITION>::call([&](SYS_CALLIF_AUTO) { ... });
32 ///
33 /// @note Your lambda must have exactly 1 parameter of type SYS_CALLIF_AUTO
34 /// @{
35 template<bool CONDITION>
36 struct SYS_CallIf
37 {
38  template<typename FUNCTOR, typename... ARGS>
39  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
40  {
41  // No call at all if CONDITION is false
42  }
43 };
44 
45 template<>
46 struct SYS_CallIf<true>
47 {
48 #if SYS_HAS_CXX14
49  template<typename FUNCTOR, typename... ARGS>
50  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
51  {
52  struct dummy {};
53  functor(dummy(), std::forward<ARGS>(args)...);
54  }
55 #else
56  template<typename FUNCTOR, typename... ARGS>
57  static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS&&... args)
58  {
59  functor(std::forward<ARGS>(args)...);
60  }
61 #endif
62 };
63 /// @}
64 
65 #endif // __SYS_CALLIF_H_INCLUDED__
static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS &&...args)
Definition: SYS_CallIf.h:39
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
static SYS_FORCE_INLINE void call(FUNCTOR functor, ARGS &&...args)
Definition: SYS_CallIf.h:57
**If you just want to fire and args
Definition: thread.h:609