Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FunctionTraits.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 namespace open3d {
30 namespace core {
31 
34 template <typename T>
35 struct FunctionTraits : public FunctionTraits<decltype(&T::operator())> {};
36 
52 template <typename ClassType, typename T>
53 struct FunctionTraits<T ClassType::*> : public FunctionTraits<T> {};
54 
55 // Const class member functions
56 template <typename ClassType, typename ReturnType, typename... Args>
57 struct FunctionTraits<ReturnType (ClassType::*)(Args...) const>
58  : public FunctionTraits<ReturnType(Args...)> {};
59 
60 // Reference types
61 template <typename T>
62 struct FunctionTraits<T&> : public FunctionTraits<T> {};
63 template <typename T>
64 struct FunctionTraits<T*> : public FunctionTraits<T> {};
65 
66 // Free functions
67 template <typename ReturnType, typename... Args>
68 struct FunctionTraits<ReturnType(Args...)> {
69  // arity is the number of arguments.
70  enum { arity = sizeof...(Args) };
71 
72  typedef std::tuple<Args...> ArgsTuple;
73  typedef ReturnType result_type;
74 
75  template <size_t i>
76  struct arg {
77  typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
78  // the i-th argument is equivalent to the i-th tuple element of a tuple
79  // composed of those arguments.
80  };
81 };
82 
83 template <typename T>
85  using traits = FunctionTraits<T>;
86  using res_t = typename traits::result_type;
87 };
88 
89 template <typename T>
91  using traits = FunctionTraits<T>;
92  using res_t = typename traits::result_type;
93  using arg0_t = typename traits::template arg<0>::type;
94 };
95 
96 template <typename T>
98  using traits = FunctionTraits<T>;
99  using res_t = typename traits::result_type;
100  using arg0_t = typename traits::template arg<0>::type;
101  using arg1_t = typename traits::template arg<1>::type;
102 };
103 
104 } // namespace core
105 } // namespace open3d
std::tuple< Args... > ArgsTuple
Definition: FunctionTraits.h:72
FunctionTraits< T > traits
Definition: FunctionTraits.h:98
FunctionTraits< T > traits
Definition: FunctionTraits.h:85
Definition: FunctionTraits.h:35
std::tuple_element< i, std::tuple< Args... > >::type type
Definition: FunctionTraits.h:77
FunctionTraits< T > traits
Definition: FunctionTraits.h:91
typename traits::result_type res_t
Definition: FunctionTraits.h:92
char type
Definition: FilePCD.cpp:60
typename traits::result_type res_t
Definition: FunctionTraits.h:86
typename traits::result_type res_t
Definition: FunctionTraits.h:99
Definition: FunctionTraits.h:97
Definition: FunctionTraits.h:90
Definition: PinholeCameraIntrinsic.cpp:35
ReturnType result_type
Definition: FunctionTraits.h:73
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:93
Definition: FunctionTraits.h:84
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:100
typename traits::template arg< 1 >::type arg1_t
Definition: FunctionTraits.h:101