Open3D (C++ API)  0.11.0
FuncionTraits.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 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 
51 template <typename ClassType, typename T>
52 struct FunctionTraits<T ClassType::*> : public FunctionTraits<T> {};
53 
54 // Const class member functions
55 template <typename ClassType, typename ReturnType, typename... Args>
56 struct FunctionTraits<ReturnType (ClassType::*)(Args...) const>
57  : public FunctionTraits<ReturnType(Args...)> {};
58 
59 // Reference types
60 template <typename T>
61 struct FunctionTraits<T&> : public FunctionTraits<T> {};
62 template <typename T>
63 struct FunctionTraits<T*> : public FunctionTraits<T> {};
64 
65 // Free functions
66 template <typename ReturnType, typename... Args>
67 struct FunctionTraits<ReturnType(Args...)> {
68  // arity is the number of arguments.
69  enum { arity = sizeof...(Args) };
70 
71  typedef std::tuple<Args...> ArgsTuple;
72  typedef ReturnType result_type;
73 
74  template <size_t i>
75  struct arg {
76  typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
77  // the i-th argument is equivalent to the i-th tuple element of a tuple
78  // composed of those arguments.
79  };
80 };
81 
82 template <typename T>
84  using traits = FunctionTraits<T>;
85  using res_t = typename traits::result_type;
86 };
87 
88 template <typename T>
90  using traits = FunctionTraits<T>;
91  using res_t = typename traits::result_type;
92  using arg0_t = typename traits::template arg<0>::type;
93 };
94 
95 template <typename T>
97  using traits = FunctionTraits<T>;
98  using res_t = typename traits::result_type;
99  using arg0_t = typename traits::template arg<0>::type;
100  using arg1_t = typename traits::template arg<1>::type;
101 };
102 
103 } // namespace core
104 } // namespace open3d
std::tuple< Args... > ArgsTuple
Definition: FuncionTraits.h:71
FunctionTraits< T > traits
Definition: FuncionTraits.h:97
FunctionTraits< T > traits
Definition: FuncionTraits.h:84
Definition: FuncionTraits.h:35
std::tuple_element< i, std::tuple< Args... > >::type type
Definition: FuncionTraits.h:76
FunctionTraits< T > traits
Definition: FuncionTraits.h:90
typename traits::result_type res_t
Definition: FuncionTraits.h:91
typename traits::result_type res_t
Definition: FuncionTraits.h:85
typename traits::result_type res_t
Definition: FuncionTraits.h:98
char type
Definition: FilePCD.cpp:60
Definition: FuncionTraits.h:96
Definition: FuncionTraits.h:89
Definition: PinholeCameraIntrinsic.cpp:35
ReturnType result_type
Definition: FuncionTraits.h:72
typename traits::template arg< 0 >::type arg0_t
Definition: FuncionTraits.h:92
Definition: FuncionTraits.h:83
typename traits::template arg< 0 >::type arg0_t
Definition: FuncionTraits.h:99
typename traits::template arg< 1 >::type arg1_t
Definition: FuncionTraits.h:100