HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
functionTraits.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TF_FUNCTION_TRAITS_H
9 #define PXR_BASE_TF_FUNCTION_TRAITS_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/base/tf/meta.h"
14 
15 #include <cstddef>
16 #include <tuple>
17 #include <type_traits>
18 
20 
21 // Function signature representation.
22 template <class Ret, class ArgTypeList>
23 struct Tf_FuncSig
24 {
25  using ReturnType = Ret;
26  using ArgTypes = ArgTypeList;
29 
30  template <size_t N>
31  using NthArg = std::tuple_element_t<N, ArgsTuple>;
32 };
33 
34 // Produce a new Tf_FuncSig from FuncSig by removing the initial "this"
35 // argument.
36 template <class FuncSig>
38  typename FuncSig::ReturnType,
40 
41 // For callable function objects, get signature from operator(), but remove the
42 // 'this' arg from that.
43 template <class Fn>
45 {
46  using Type = Tf_RemoveThisArg<
47  typename Tf_GetFuncSig<
48  decltype(&std::remove_reference<Fn>::type::operator())
49  >::Type
50  >;
51 };
52 
53 // Member function pointers, with optional 'const' and ref-qualifiers.
54 template <class Ret, class Cls, class... Args>
55 struct Tf_GetFuncSig<Ret (Cls::*)(Args...)>
56 {
57  using Type = Tf_FuncSig<Ret, TfMetaList<Cls &, Args...>>;
58 };
59 template <class Ret, class Cls, class... Args>
60 struct Tf_GetFuncSig<Ret (Cls::*)(Args...) &>
61 {
62  using Type = Tf_FuncSig<Ret, TfMetaList<Cls &, Args...>>;
63 };
64 template <class Ret, class Cls, class... Args>
65 struct Tf_GetFuncSig<Ret (Cls::*)(Args...) &&>
66 {
67  using Type = Tf_FuncSig<Ret, TfMetaList<Cls &&, Args...>>;
68 };
69 
70 template <class Ret, class Cls, class... Args>
71 struct Tf_GetFuncSig<Ret (Cls::*)(Args...) const>
72 {
73  using Type = Tf_FuncSig<Ret, TfMetaList<Cls const &, Args...>>;
74 };
75 template <class Ret, class Cls, class... Args>
76 struct Tf_GetFuncSig<Ret (Cls::*)(Args...) const &>
77 {
78  using Type = Tf_FuncSig<Ret, TfMetaList<Cls const &, Args...>>;
79 };
80 template <class Ret, class Cls, class... Args>
81 struct Tf_GetFuncSig<Ret (Cls::*)(Args...) const &&>
82 {
83  using Type = Tf_FuncSig<Ret, TfMetaList<Cls const &&, Args...>>;
84 };
85 
86 // Regular function pointers.
87 template <class Ret, class... Args>
88 struct Tf_GetFuncSig<Ret (*)(Args...)>
89 {
90  using Type = Tf_FuncSig<Ret, TfMetaList<Args...>>;
91 };
92 
93 // Function traits.
94 template <class Fn>
96 
98 
99 #endif // PXR_BASE_TF_FUNCTION_TRAITS_H
100 
std::tuple_element_t< N, ArgsTuple > NthArg
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static const size_t Arity
ArgTypeList ArgTypes
typename Tf_GetFuncSig< Fn >::Type TfFunctionTraits
TfMetaApply< std::tuple, ArgTypes > ArgsTuple
typename Tf_MetaApplyImpl< Cls, TypeList >::Type TfMetaApply
Definition: meta.h:36