Open3D (C++ API)  0.15.1
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
29namespace open3d {
30namespace core {
31
34template <typename T>
35struct FunctionTraits : public FunctionTraits<decltype(&T::operator())> {};
36
52template <typename ClassType, typename T>
53struct FunctionTraits<T ClassType::*> : public FunctionTraits<T> {};
54
55// Const class member functions
56template <typename ClassType, typename ReturnType, typename... Args>
57struct FunctionTraits<ReturnType (ClassType::*)(Args...) const>
58 : public FunctionTraits<ReturnType(Args...)> {};
59
60// Reference types
61template <typename T>
62struct FunctionTraits<T&> : public FunctionTraits<T> {};
63template <typename T>
64struct FunctionTraits<T*> : public FunctionTraits<T> {};
65
66// Free functions
67template <typename ReturnType, typename... Args>
68struct 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
83template <typename T>
86 using res_t = typename traits::result_type;
87};
88
89template <typename T>
92 using res_t = typename traits::result_type;
93 using arg0_t = typename traits::template arg<0>::type;
94};
95
96template <typename 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
char type
Definition: FilePCD.cpp:60
Definition: PinholeCameraIntrinsic.cpp:35
Definition: FunctionTraits.h:97
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:100
typename traits::result_type res_t
Definition: FunctionTraits.h:99
typename traits::template arg< 1 >::type arg1_t
Definition: FunctionTraits.h:101
std::tuple_element< i, std::tuple< Args... > >::type type
Definition: FunctionTraits.h:77
ReturnType result_type
Definition: FunctionTraits.h:73
std::tuple< Args... > ArgsTuple
Definition: FunctionTraits.h:72
Definition: FunctionTraits.h:35
Definition: FunctionTraits.h:84
typename traits::result_type res_t
Definition: FunctionTraits.h:86
Definition: FunctionTraits.h:90
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:93
typename traits::result_type res_t
Definition: FunctionTraits.h:92