Open3D (C++ API)  0.18.0+5c982c7
FunctionTraits.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 namespace open3d {
11 namespace core {
12 
15 template <typename T>
16 struct FunctionTraits : public FunctionTraits<decltype(&T::operator())> {};
17 
33 template <typename ClassType, typename T>
34 struct FunctionTraits<T ClassType::*> : public FunctionTraits<T> {};
35 
36 // Const class member functions
37 template <typename ClassType, typename ReturnType, typename... Args>
38 struct FunctionTraits<ReturnType (ClassType::*)(Args...) const>
39  : public FunctionTraits<ReturnType(Args...)> {};
40 
41 // Reference types
42 template <typename T>
43 struct FunctionTraits<T&> : public FunctionTraits<T> {};
44 template <typename T>
45 struct FunctionTraits<T*> : public FunctionTraits<T> {};
46 
47 // Free functions
48 template <typename ReturnType, typename... Args>
49 struct FunctionTraits<ReturnType(Args...)> {
50  // arity is the number of arguments.
51  enum { arity = sizeof...(Args) };
52 
53  typedef std::tuple<Args...> ArgsTuple;
54  typedef ReturnType result_type;
55 
56  template <size_t i>
57  struct arg {
58  typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
59  // the i-th argument is equivalent to the i-th tuple element of a tuple
60  // composed of those arguments.
61  };
62 };
63 
64 template <typename T>
67  using res_t = typename traits::result_type;
68 };
69 
70 template <typename T>
73  using res_t = typename traits::result_type;
74  using arg0_t = typename traits::template arg<0>::type;
75 };
76 
77 template <typename T>
80  using res_t = typename traits::result_type;
81  using arg0_t = typename traits::template arg<0>::type;
82  using arg1_t = typename traits::template arg<1>::type;
83 };
84 
85 } // namespace core
86 } // namespace open3d
char type
Definition: FilePCD.cpp:41
Definition: PinholeCameraIntrinsic.cpp:16
Definition: FunctionTraits.h:78
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:81
typename traits::result_type res_t
Definition: FunctionTraits.h:80
typename traits::template arg< 1 >::type arg1_t
Definition: FunctionTraits.h:82
std::tuple_element< i, std::tuple< Args... > >::type type
Definition: FunctionTraits.h:58
ReturnType result_type
Definition: FunctionTraits.h:54
std::tuple< Args... > ArgsTuple
Definition: FunctionTraits.h:53
Definition: FunctionTraits.h:16
Definition: FunctionTraits.h:65
typename traits::result_type res_t
Definition: FunctionTraits.h:67
Definition: FunctionTraits.h:71
typename traits::template arg< 0 >::type arg0_t
Definition: FunctionTraits.h:74
typename traits::result_type res_t
Definition: FunctionTraits.h:73