xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
xtd.core
include
xtd
internal
__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
12
namespace
xtd
{
29
template
<
typename
new_type,
typename
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
<
typename
new_type,
typename
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
<
typename
new_type,
typename
current_type>
60
requires
std::is_null_pointer_v<new_type>
61
[[nodiscard]]
auto
as
(current_type& value) -> new_type& {
62
if
(!std::is_null_pointer_v<current_type>)
xtd::helpers::throw_helper::throws
(
xtd::helpers::exception_case::invalid_cast
);
63
return
value;
64
}
66
82
template
<
typename
new_type,
typename
current_type>
83
[[nodiscard]]
inline
auto
as
(
const
current_type* value) ->
const
new_type* {
84
return
xtd::convert_pointer::to_ptr<new_type>
(value);
85
}
86
102
template
<
typename
new_type,
typename
current_type>
103
[[nodiscard]]
auto
as
(current_type* value) -> new_type* {
104
return
xtd::convert_pointer::to_ptr<new_type>
(value);
105
}
106
123
template
<
typename
new_type,
typename
current_type>
124
[[nodiscard]]
auto
as
(
xtd::uptr<current_type>
& value) ->
xtd::uptr<new_type>
{
125
return
xtd::convert_pointer::to_unique_ptr<new_type>
(value);
126
}
127
143
template
<
typename
new_type,
typename
current_type>
144
[[nodiscard]]
auto
as
(
xtd::uptr<current_type>
&& value) ->
xtd::uptr<new_type>
{
145
return
xtd::convert_pointer::to_unique_ptr<new_type>
(value);
146
}
147
164
template
<
typename
new_type,
typename
current_type>
165
[[nodiscard]]
auto
as
(
const
xtd::sptr<current_type>
& value) ->
xtd::sptr<new_type>
{
166
return
xtd::convert_pointer::to_shared_ptr<new_type>
(value);
167
}
168
184
template
<
typename
new_type,
typename
current_type>
185
[[nodiscard]]
auto
as
(
xtd::sptr<current_type>
& value) ->
xtd::sptr<new_type>
{
186
return
xtd::convert_pointer::to_shared_ptr<new_type>
(value);
187
}
188
205
template
<
typename
new_type,
typename
current_type>
206
[[nodiscard]]
auto
as
(
xtd::sptr<current_type>
&& value) ->
xtd::sptr<new_type>
{
207
return
xtd::convert_pointer::to_shared_ptr<new_type>
(value);
208
}
209
}
xtd::helpers::throw_helper::throws
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
xtd::helpers::exception_case::invalid_cast
@ invalid_cast
The cast is not valid.
Definition
exception_case.hpp:63
xtd::sptr
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition
sptr.hpp:25
xtd::uptr
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition
uptr.hpp:25
xtd::convert_pointer::to_ptr
static auto to_ptr(const current_type *value) -> const new_type *
Casts a type into another type.
Definition
convert_pointer.hpp:43
xtd::as
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition
__as_any_object.hpp:60
xtd::convert_pointer::to_unique_ptr
static auto to_unique_ptr(xtd::uptr< current_type > &value) -> xtd::uptr< new_type >
Casts a type into another type.
Definition
convert_pointer.hpp:366
xtd::convert_pointer::to_shared_ptr
static auto to_shared_ptr(const xtd::sptr< current_type > &value) -> xtd::sptr< new_type >
Casts a type into another type.
Definition
convert_pointer.hpp:250
xtd::console_key::e
@ e
The E key.
Definition
console_key.hpp:96
xtd
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition
abstract_object.hpp:8
Generated on
for xtd by
Gammasoft
. All rights reserved.