HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Tuple.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  * COMMENTS:
7  * This file defines a number of functions named UTlhsTuple() (tuples
8  * that are valid left hand sides in assignments). These functions
9  * are inspired by python, where it's very easy to return multiple values
10  * from a function:
11  *
12  * def foo():
13  * return ([0, 1, 2], 6)
14  *
15  * (a, b) = foo()
16  * ...do something with a and b...
17  *
18  * The C++ equivalent works with boost tuples, and looks like:
19  *
20  * static UT_Tuple<UT_Vector3, int> foo()
21  * { return UTmakeTuple(UT_Vector3(0, 1, 2), 6); }
22  *
23  * UT_Vector3 a;
24  * int b;
25  * UTlhsTuple(a, b) = foo();
26  * ...do something with a and b...
27  *
28  * One handy use of these functions is when you want to pass multiple
29  * values into a callback function that takes a void *. Instead of
30  * creating a struct to hold the values, pass in a pointer to a
31  * UT_Tuple
32  * void iterateOverSomething(
33  * void (*callback)(void *), void *callback_data));
34  *
35  * static void my_callback(void *data)
36  * {
37  * UT_Vector3 a;
38  * int b;
39  * UTlhsTuple(a, b) = *(UT_Tuple<UT_Vector3, int>*)data;
40  * ...do something with a and b...
41  * }
42  *
43  * UT_Tuple<UT_Vector3, int> data(UT_Vector3(1,2,3), 4);
44  * iterateOverSomething(my_callback, &data);
45  */
46 
47 #ifndef __UT_TUPLE_H_INCLUDED__
48 #define __UT_TUPLE_H_INCLUDED__
49 
50 #include <tuple>
51 
52 template <class... Types>
53 using UT_Tuple = std::tuple<Types...>;
54 
55 #define UTtupleIgnore std::ignore
56 
57 #define UTtupleGet std::get
58 
59 #define UTmakeTuple std::make_tuple
60 
61 #define UTlhsTuple std::tie
62 
63 #endif // __UT_TUPLE_H_INCLUDED__
std::tuple< Types...> UT_Tuple
Definition: UT_Tuple.h:53