HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TupleUtil.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: UT_TupleUtil.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_TUPLEUTIL_H_INCLUDED__
12 #define __UT_TUPLEUTIL_H_INCLUDED__
13 
14 #include "UT_API.h"
15 
16 #include <tuple>
17 #include <type_traits>
18 #include <utility>
19 #include <stddef.h>
20 
21 namespace UT_TupleUtilImpl
22 {
23  template <typename T, typename F, size_t I, size_t N>
24  struct AnyOf;
25 
26  // Base case for last element
27  template <typename T, typename F, size_t N>
28  struct AnyOf<T, F, N, N>
29  {
30  bool operator()(T&& tuple, F&& f)
31  {
32  return false;
33  }
34  };
35 
36  // Recursive case
37  template <typename T, typename F, size_t I, size_t N>
38  struct AnyOf
39  {
40  bool operator()(T&& tuple, F&& f)
41  {
42  if (f(std::get<I>(std::forward<T>(tuple))))
43  return true;
44  return AnyOf<T, F, I+1, N>()(std::forward<T>(tuple),
45  std::forward<F>(f));
46  }
47  };
48 
49  template <typename T, typename F, size_t I, size_t N>
50  struct ForEach;
51 
52  // Base case for last element
53  template <typename T, typename F, size_t N>
54  struct ForEach<T, F, N, N>
55  {
56  void operator()(T&& tuple, F&& f)
57  {
58  }
59  };
60 
61  // Recursive case
62  template <typename T, typename F, size_t I, size_t N>
63  struct ForEach
64  {
65  void operator()(T&& tuple, F&& f)
66  {
67  f(std::get<I>(std::forward<T>(tuple)));
68  ForEach<T, F, I+1, N>()(std::forward<T>(tuple), std::forward<F>(f));
69  }
70  };
71 }
72 
73 /// Invoke functor f for each element e in a tuple, returning true as soon as
74 /// f(e) returns true. Returns false when f(e) is false for all elements.
75 ///
76 /// @note This is like std::any_of() except for tuples.
77 /// @note The tuple need not be std::tuple, and instead may be anything that
78 /// supports std::get and std::tuple_size; in particular, std::array and
79 /// std::pair may be used.
80 template <typename T, typename F>
81 bool
82 UTtupleAnyOf(T&& tuple, F&& f)
83 {
86  std::forward<T>(tuple), std::forward<F>(f));
87 }
88 
89 /// Invoke functor f for each element e in a tuple.
90 ///
91 /// @note This is like std::for_each() except for tuples.
92 /// @note The tuple need not be std::tuple, and instead may be anything that
93 /// supports std::get and std::tuple_size; in particular, std::array and
94 /// std::pair may be used.
95 template <typename T, typename F>
96 void
97 UTtupleForEach(T&& tuple, F&& f)
98 {
101  std::forward<T>(tuple), std::forward<F>(f));
102 }
103 
104 #endif // __UT_TUPLEUTIL_H_INCLUDED__
bool operator()(T &&tuple, F &&f)
Definition: UT_TupleUtil.h:40
bool UTtupleAnyOf(T &&tuple, F &&f)
Definition: UT_TupleUtil.h:82
GLfloat f
Definition: glcorearb.h:1925
void operator()(T &&tuple, F &&f)
Definition: UT_TupleUtil.h:65
bool operator()(T &&tuple, F &&f)
Definition: UT_TupleUtil.h:30
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GA_API const UT_StringHolder N
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
void UTtupleForEach(T &&tuple, F &&f)
Definition: UT_TupleUtil.h:97