MCPcopy Create free account
hub / github.com/covscript/covscript / cni_decayed_convertor

Class cni_decayed_convertor

include/covscript/core/cni.hpp:269–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267
268 template <typename _SourceT, typename _TargetT>
269 class cni_decayed_convertor {
270 private:
271 template <typename _From, typename _To, typename = void>
272 struct is_specialized
273 {
274 static constexpr bool value = true;
275 };
276
277 template <typename _From, typename _To>
278 struct is_specialized<_From, _To, void_t<typename type_convertor<_From, _To>::_not_specialized>>
279 {
280 static constexpr bool value = false;
281 };
282
283 template <typename>
284 struct type_extractor;
285
286 template <template <typename, typename> class T, typename _From, typename _To>
287 struct type_extractor<T<_From, _To>>
288 {
289 using source_type = _From;
290 using target_type = _To;
291 };
292
293 template <typename S, typename T>
294 using select_convertor = typename std::conditional<is_specialized<S, T>::value,
295 type_convertor<S, T>, typename std::conditional<is_specialized<decay_t<S>, decay_t<T>>::value, type_convertor<decay_t<S>, decay_t<T>>, typename std::conditional<cni_convertible<S, T>::value, type_convertor<S, T>, void>::type>::type>::type;
296
297 public:
298 using convertor = select_convertor<_SourceT, _TargetT>;
299 static_assert(!std::is_same<convertor, void>::value, "No suitable type_convertor found.");
300
301 using source_type = typename type_extractor<convertor>::source_type;
302 using target_type = typename type_extractor<convertor>::target_type;
303
304 static _TargetT convert_to_cpp(any &val)
305 {
306 constexpr bool bindable = std::is_reference<decltype(convertor::convert(std::declval<source_type>()))>::value || !std::is_reference<_TargetT>::value;
307 using Convertor = cni_decayed_converter_impl<source_type, _TargetT, convertor, bindable>;
308 return Convertor::convert(val);
309 }
310
311 template <typename T>
312 static any convert_to_cs(T &&val)
313 {
314 return return_to_cs(convertor::convert(std::forward<T>(val)));
315 }
316 };
317
318// Dynamic argument check
319 template <typename T, int index>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected