-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathbase_collections_input_vector.h
99 lines (79 loc) · 2.6 KB
/
base_collections_input_vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
namespace winrt::impl
{
template <typename T, typename Container, typename ThreadingBase>
struct vector_impl :
implements<vector_impl<T, Container, ThreadingBase>, wfc::IVector<T>, wfc::IVectorView<T>, wfc::IIterable<T>>,
vector_base<vector_impl<T, Container, ThreadingBase>, T>,
ThreadingBase
{
static_assert(std::is_same_v<Container, std::remove_reference_t<Container>>, "Must be constructed with rvalue.");
explicit vector_impl(Container&& values) : m_values(std::forward<Container>(values))
{
}
auto& get_container() noexcept
{
return m_values;
}
auto& get_container() const noexcept
{
return m_values;
}
using ThreadingBase::acquire_shared;
using ThreadingBase::acquire_exclusive;
private:
Container m_values;
};
template <typename T, typename Container>
using input_vector = vector_impl<T, Container, single_threaded_collection_base>;
}
WINRT_EXPORT namespace winrt::param
{
template <typename T>
struct vector
{
using value_type = T;
using interface_type = Windows::Foundation::Collections::IVector<value_type>;
vector(std::nullptr_t) noexcept
{
}
vector(vector const& values) = delete;
vector& operator=(vector const& values) = delete;
vector(interface_type const& values) noexcept : m_owned(false)
{
attach_abi(m_interface, winrt::get_abi(values));
}
template <typename Collection, std::enable_if_t<std::is_convertible_v<Collection, interface_type>, int> = 0>
vector(Collection const& values) noexcept
{
m_interface = values;
}
template <typename Allocator>
vector(std::vector<value_type, Allocator>&& values) :
m_interface(make<impl::input_vector<value_type, std::vector<value_type, Allocator>>>(std::move(values)))
{
}
vector(std::initializer_list<value_type> values) :
m_interface(make<impl::input_vector<value_type, std::vector<value_type>>>(values))
{
}
~vector() noexcept
{
if (!m_owned)
{
detach_abi(m_interface);
}
}
operator interface_type const& () const noexcept
{
return m_interface;
}
private:
interface_type m_interface;
bool m_owned = true;
};
template <typename T>
auto get_abi(vector<T> const& object) noexcept
{
return *(void**)(&object);
}
}