CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
func.h
1
3#pragma once
4
5#include "defines.h"
6#include <functional>
7#include <tuple>
8#include <utility>
9#include "system/multicast_delegate.h"
10
11namespace System
12{
13namespace Detail
14{
15
19 template <typename Reordered, typename ...FuncArgs> struct FuncArgsReorderer;
20
26 template <typename ...ReorderedArgs, typename FirstArg, typename ...OtherArgs>
27 struct FuncArgsReorderer<void(ReorderedArgs...), FirstArg, OtherArgs...>
28 : FuncArgsReorderer<void(ReorderedArgs..., FirstArg), OtherArgs...>
29 {};
30
35 template <typename ...ReorderedArgs, typename ReturnType>
36 struct FuncArgsReorderer<void(ReorderedArgs...), ReturnType>
37 {
39 using type = ReturnType(ReorderedArgs...);
40 };
41
42} // namespace Detail
43
80template<typename... Args>
81class Func : public MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>
82{
83 // There's no way to avoid using external template argument parser class as argument pack must be the last template argument, and in .Net Func arguments preceded the return value.
84 // Also, there's no way to just alias MulticastDelegate, as this way deducing Func arguments doesn't work, and we have LINQ tests where it should.
85public:
88 : MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>()
89 {}
93 template <typename T>
94 Func(T &&arg)
95 : MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>(arg)
96 {}
99 Func(const Func &func)
100 : MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>(func)
101 {}
104 Func(Func &&func) noexcept
105 : MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>(std::move(func))
106 {}
109 {}
110
114 Func& operator = (const Func &other)
115 {
116 MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>::operator = (other);
117 return *this;
118 }
122 Func& operator = (Func &&other) noexcept
123 {
124 MulticastDelegate<typename ::System::Detail::FuncArgsReorderer<void(), Args...>::type>::operator = (std::move(other));
125 return *this;
126 }
127};
128
129} // namespace System
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
~Func()
Destructor.
Definition: func.h:108
Func(const Func &func)
Copy constructor.
Definition: func.h:99
Func(Func &&func) noexcept
Move constructor.
Definition: func.h:104
Func(T &&arg)
Constructor that constructs Func object and assigns value (either actual callback or nullptr) to it.
Definition: func.h:94
Func & operator=(const Func &other)
Copy assignment.
Definition: func.h:114
Func()
Default constructor that creates null-Func.
Definition: func.h:87
Definition: db_command.h:9