xtd 0.2.0
Loading...
Searching...
No Matches
__as_pointer.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#if !defined(__XTD_CORE_INTERNAL__)
7#error "Do not include this file: Internal use only"
8#endif
10
12namespace xtd {
29 template<class new_type, class current_type>
30 [[nodiscard]] auto as(const current_type& value) -> const new_type& {
31 thread_local static __as_enum__<new_type, current_type, typename std::is_enum<current_type>::type> e;
32 return e.convert(value);
33 }
34
51 template<class new_type, class current_type>
52 requires (!std::is_null_pointer_v<new_type>)
53 [[nodiscard]] auto as(current_type& value) -> new_type& {
54 thread_local static __as_enum__<new_type, current_type, typename std::is_enum<current_type>::type> e;
55 return e.convert(value);
56 }
57
59 template<class new_type, class current_type>
60 requires std::is_null_pointer_v<new_type>
61 [[nodiscard]] auto as(current_type& value) -> new_type& {
63 return value;
64 }
66
82 template<class new_type, class current_type>
83 [[nodiscard]] inline auto as(const current_type* value) -> const new_type* {
85 }
86
102 template<class new_type, class current_type>
103 [[nodiscard]] auto as(current_type* value) -> new_type* {
105 }
106
123 template<class new_type, class current_type>
124 [[nodiscard]] auto as(xtd::uptr<current_type>& value) -> xtd::uptr<new_type> {
126 }
127
143 template<class new_type, class current_type>
144 [[nodiscard]] auto as(xtd::uptr<current_type>&& value) -> xtd::uptr<new_type> {
146 }
147
164 template<class new_type, class current_type>
165 [[nodiscard]] auto as(const xtd::sptr<current_type>& value) -> xtd::sptr<new_type> {
167 }
168
184 template<class new_type, class current_type>
185 [[nodiscard]] auto as(xtd::sptr<current_type>& value) -> xtd::sptr<new_type> {
187 }
188
205 template<class new_type, class current_type>
206 [[nodiscard]] auto as(xtd::sptr<current_type>&& value) -> xtd::sptr<new_type> {
208 }
209}
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
@ invalid_cast
The cast is not valid.
Definition exception_case.hpp:63
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
static xtd::uptr< new_type > to_unique_ptr(xtd::uptr< current_type > &value)
Casts a type into another type.
Definition convert_pointer.hpp:368
static const new_type * to_ptr(const current_type *value)
Casts a type into another type.
Definition convert_pointer.hpp:45
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition __as_any_object.hpp:60
static xtd::sptr< new_type > to_shared_ptr(const xtd::sptr< current_type > &value)
Casts a type into another type.
Definition convert_pointer.hpp:252
@ e
The E key.
Definition console_key.hpp:96
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8