xtd 0.2.0
Loading...
Searching...
No Matches
__as_enum.h
Go to the documentation of this file.
1
3#pragma once
5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
7#endif
9
10#include "../convert_pointer.h"
11
13template<typename new_type_t, typename current_type_t, typename bool_t>
14struct __as_enum__ {};
15
16template<typename new_type_t, typename current_type_t>
17struct __as_enum__<new_type_t, current_type_t, std::true_type> {
18 const new_type_t& convert(const current_type_t& value) {
19 __result__ = static_cast<new_type_t>(value);
20 return __result__;
21 }
22 new_type_t& convert(current_type_t& value) {
23 __result__ = static_cast<new_type_t>(value);
24 return __result__;
25 }
26 thread_local inline static new_type_t __result__ {};
27};
28
29template<typename new_type_t, typename current_type_t>
30struct __as_enum__<new_type_t, current_type_t, std::false_type> {
31 const new_type_t& convert(const current_type_t& value) {
32 return xtd::convert_pointer::to_ref<new_type_t>(value);
33 }
34 new_type_t& convert(current_type_t& value) {
35 return xtd::convert_pointer::to_ref<new_type_t>(value);
36 }
37};