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