CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
detail.h
1
2#pragma once
3
4#include <type_traits>
5#include <utility>
6#include <ostream>
7
8namespace System { namespace detail {
9
13template <class From, class To, class = decltype(static_cast<To*>((From*)nullptr))>
14std::true_type IsStaticCastable_Internal(int);
18template <class From, class To>
19std::false_type IsStaticCastable_Internal(...);
20
25template <class From, class To>
26using is_static_castable = decltype(IsStaticCastable_Internal<From, To>(0));
27
32template <typename From, typename To, bool convertible = is_static_castable<From, To>::value>
34{
38 static To* cast(From *pointer) { return dynamic_cast<To*>(pointer); }
39};
40
45template <typename From, typename To>
46struct cast_statically_or_dynamically<From, To, true>
47{
51 static To* cast(From *pointer) { return static_cast<To*>(pointer); }
52};
53
54
58template <template <class ...T> class TypeToBe>
60{
62 static std::false_type Invoke(...);
65 template <typename ...P>
66 static std::true_type Invoke(const TypeToBe<P...>*);
67
70 template <typename Tested>
71 using type = decltype(Invoke((Tested*)nullptr));
72};
73
79template <typename Tested, template <class ...T> class TypeToBe>
80struct is_a : public Is_A_Internal<TypeToBe>::template type<Tested> {};
82template <typename Tested, template <class ...T> class TypeToBe>
83struct is_a<Tested&, TypeToBe> : public Is_A_Internal<TypeToBe>::template type<Tested> {};
85template <typename Tested, template <class ...T> class TypeToBe>
86struct is_a<Tested&&, TypeToBe> : public Is_A_Internal<TypeToBe>::template type<Tested> {};
87
88
94template<typename T, typename Sfinae = void>
95struct has_operator_less : std::false_type {};
97template<typename T>
99 T
100 , decltype((void)(std::declval<T&>() < std::declval<T&>()))
101> : std::true_type{};
102
103
106template <class T>
108{
109 template <class U>
110 static auto test(U*) -> decltype(std::declval<U>() == std::declval<U>());
111 template <typename>
112 static auto test(...) -> std::false_type;
113
114 using type = typename std::is_same<bool, decltype(test<T>(0))>::type;
115};
116
121template <class T>
123
128template <class T, class U>
129struct has_no_operator_equal : std::integral_constant<bool, !has_operator_equal<T>::value && !has_operator_equal<U>::value> {};
130
136template<typename T, typename Sfinae = void>
137struct has_method_equals : std::false_type {};
139template<typename T>
140struct has_method_equals<
141 T
142 , decltype((void)(std::declval<T&>().Equals(std::declval<T&>())))
143> : std::true_type{};
144
145
149template<typename T>
150using has_only_method_equals = std::integral_constant<bool, has_method_equals<T>::value && !has_operator_equal<T>::value>;
151
152
158template<typename T, typename Sfinae = void>
159struct has_method_gethashcode : std::false_type {};
161template<typename T>
163 T
164 , decltype((void)(std::declval<T&>().GetHashCode()))
165> : std::true_type {};
166
167
173template<typename T, typename Sfinae = void>
174struct has_ref_method_gethashcode : std::false_type {};
176template<typename T>
178 T
179 , decltype((void)(std::declval<T&>()->GetHashCode()))
180> : std::true_type {};
181
182
188template<typename T, typename Sfinae = void>
189struct has_method_compareto_via_dot : std::false_type {};
191template<typename T>
193 T
194 , decltype((void)(std::declval<T&>().CompareTo(*static_cast<T*>(nullptr))))
195> : std::true_type {};
196
197
203template<typename T, typename Sfinae = void>
204struct has_method_compareto_via_arrow : std::false_type {};
206template<typename T>
208 T
209 , decltype((void)(std::declval<T&>()->CompareTo(*static_cast<T*>(nullptr))))
210> : std::true_type {};
211
217template<typename T, typename Sfinae = void>
218struct has_method_get_Count : std::false_type {};
220template<typename T>
222 T
223 , decltype((void)(std::declval<T&>()->get_Count()))
224> : std::true_type {};
225
231template<typename T, typename Sfinae = void>
232struct has_print_to_function : std::false_type {};
234template<typename T>
236 T
237 , decltype((void)(PrintTo(std::declval<T&>(), std::declval<std::ostream*>())))
238> : std::true_type{};
239
245template<typename T, typename Sfinae = void>
246struct has_method_is_null : std::false_type {};
248template<typename T>
249struct has_method_is_null<
250 T
251 , decltype((void)(std::declval<T&>().IsNull()))
252> : std::true_type {};
253
258template <typename from, typename to>
260{
262 static std::true_type check(to*);
264 static std::false_type check(...);
266 using type = decltype(check(std::declval<from*>()));
267};
268
269}} //namespace System::detail
std::true_type IsStaticCastable_Internal(int)
SFINAE to check if static_cast works between two types.
decltype(IsStaticCastable_Internal< From, To >(0)) is_static_castable
Checks if static_cast works between two types. If possible, typedefs std::true_type,...
Definition: detail.h:26
std::integral_constant< bool, has_method_equals< T >::value &&!has_operator_equal< T >::value > has_only_method_equals
Checks whether specific type has Equals method but not operator ==. If so, value member is true,...
Definition: detail.h:150
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
bool Equals(const TA &a, const TB &b)
Determines the equality of two values applying operator==() to them.
Definition: primitive_types.h:77
std::enable_if< std::is_scalar< T >::value, int >::type GetHashCode(const T &obj)
Returns a hash code for the specified scalar value.
Definition: get_hash_code.h:21
Helper class to check if specific type is a specialization of a given template.
Definition: detail.h:60
static std::true_type Invoke(const TypeToBe< P... > *)
Detects that pointee is a template specialization.
static std::false_type Invoke(...)
Detects that pointee is not a template specialization.
decltype(Invoke((Tested *) nullptr)) type
If Tested is a specialization of TypeToBe, typedefs std::true_type, otherwise typedefs std::false_typ...
Definition: detail.h:71
static To * cast(From *pointer)
Performs actual pointer casting using static_cast.
Definition: detail.h:51
Performs cheapest cast possible from static_cast and dynamic_cast.
Definition: detail.h:34
static To * cast(From *pointer)
Performs actual pointer casting using dynamic_cast.
Definition: detail.h:38
Checks whether CompareTo method exists in the specified type returned by operator ->....
Definition: detail.h:204
Checks whether CompareTo method exists in the specified type. If so, inherits std::true_type,...
Definition: detail.h:189
Checks whether Equals method exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:137
Checks whether get_Count method exists. If so, inherits std::true_type, otherwise inherits std::false...
Definition: detail.h:218
Checks whether GetHashCode method exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:159
Checks whether IsNull method exists. If so, inherits std::true_type, otherwise inherits std::false_ty...
Definition: detail.h:246
Checks whether operator == not defined neither for T, not for U types. Can be used in std::enable_if.
Definition: detail.h:129
Implementation for has_operator_equal.
Definition: detail.h:108
typename std::is_same< bool, decltype(test< T >(0))>::type type
Definition: detail.h:114
static auto test(...) -> std::false_type
static auto test(U *) -> decltype(std::declval< U >()==std::declval< U >())
Checks whether operator == exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:122
Checks whether operator < exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:95
Checks whether PrintTo function exists for specified type. If so, inherits std::true_type,...
Definition: detail.h:232
Checks whether GetHashCode method exists in type returned by specified type's operator ->....
Definition: detail.h:174
Tests if specific type is a specialization of specific template. If it is, inherits std::true_type,...
Definition: detail.h:80
Checks if pointers are implicitly convertible. Workaround for VS implementation of std::is_convertibl...
Definition: detail.h:260
static std::true_type check(to *)
SFINAE stub for possible conversions.
static std::false_type check(...)
SFINAE stub for impossible conversions.
decltype(check(std::declval< from * >())) type
Either true_type or false_type, defining whether the implicit conversion is possible.
Definition: detail.h:266