Skip to content

Commit 4ed3854

Browse files
committed
[WIP] Partial refactor of the Queue Type.
#ICE-211
1 parent c632710 commit 4ed3854

File tree

12 files changed

+808
-967
lines changed

12 files changed

+808
-967
lines changed

source/code/core/collections/public/ice/array.hxx

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,27 @@ namespace ice
3838
ValueType* _data;
3939

4040
inline explicit Array(ice::Allocator& alloc) noexcept;
41+
inline ~Array() noexcept;
42+
4143
inline Array(Array&& other) noexcept;
4244
inline Array(Array const& other) noexcept
4345
requires std::copy_constructible<Type>;
44-
inline ~Array() noexcept;
4546

4647
inline Array(
4748
ice::Allocator& alloc,
4849
ice::Span<Type const> values
4950
) noexcept requires std::copy_constructible<Type>;
5051

51-
// API Requirements Of: Container and Resizable Container
52-
template<typename Self>
53-
constexpr auto data(this Self& self) noexcept -> ice::container::ValuePtr<Self> { return self._data; }
52+
inline auto operator=(Array&& other) noexcept -> Array&;
53+
inline auto operator=(Array const& other) noexcept -> Array&
54+
requires std::copy_constructible<Type>;
55+
56+
// API Requirements Of: Container
5457
constexpr auto size() const noexcept -> ice::ncount { return { _count, sizeof(ValueType) }; }
5558

5659
// API Requirements Of: Resizable Container
60+
template<typename Self>
61+
constexpr auto data(this Self& self) noexcept -> ice::container::ValuePtr<Self> { return self._data; }
5762
constexpr auto capacity() const noexcept -> ice::ncount { return { _capacity, sizeof(ValueType) }; }
5863
constexpr void set_capacity(ice::ncount new_capacity) noexcept;
5964
constexpr void resize(ice::ncount new_size) noexcept;
@@ -65,8 +70,7 @@ namespace ice
6570
inline void push_back(ItemType&& item) noexcept;
6671

6772
template<ice::concepts::IterableContainer ContainerT>
68-
requires (std::convertible_to<ice::container::ValueType<ContainerT>, Type>
69-
&& std::is_constructible_v<Type, ice::container::ValueType<ContainerT>>)
73+
requires (ice::concepts::CompatibleContainer<Type, ContainerT>)
7074
inline void push_back(ContainerT const& other) noexcept;
7175

7276
inline void pop_back(ice::ncount count = 1_count) noexcept;
@@ -75,19 +79,13 @@ namespace ice
7579
constexpr auto data_view(this Array const& self) noexcept -> ice::Data;
7680
constexpr auto memory_view(this Array& self) noexcept -> ice::Memory;
7781

78-
inline auto operator=(Array&& other) noexcept -> Array&;
79-
inline auto operator=(Array const& other) noexcept -> Array&
80-
requires std::copy_constructible<Type>;
81-
82+
// Operators and implicit conversions
8283
inline operator ice::Span<Type>() noexcept;
8384
inline operator ice::Span<Type const>() const noexcept;
8485
};
8586

8687
template<typename Type, ice::ContainerLogic Logic>
87-
auto data_view(ice::Array<Type, Logic> const& arr) noexcept -> ice::Data
88-
{
89-
return arr.data_view();
90-
}
88+
auto data_view(ice::Array<Type, Logic> const& arr) noexcept -> ice::Data = delete;
9189

9290
template<typename Type, ice::ContainerLogic Logic>
9391
inline Array<Type, Logic>::Array(ice::Allocator& alloc) noexcept
@@ -97,6 +95,17 @@ namespace ice
9795
, _data{ nullptr }
9896
{ }
9997

98+
template<typename Type, ice::ContainerLogic Logic>
99+
inline Array<Type, Logic>::~Array() noexcept
100+
{
101+
if constexpr (Logic == ContainerLogic::Complex)
102+
{
103+
ice::mem_destruct_n_at(_data, _count);
104+
}
105+
106+
_allocator->deallocate(memory_view());
107+
}
108+
100109
template<typename Type, ice::ContainerLogic Logic>
101110
inline Array<Type, Logic>::Array(Array&& other) noexcept
102111
: _allocator{ other._allocator }
@@ -137,24 +146,12 @@ namespace ice
137146
}
138147
}
139148

140-
template<typename Type, ice::ContainerLogic Logic>
141-
inline Array<Type, Logic>::~Array() noexcept
142-
{
143-
if constexpr (Logic == ContainerLogic::Complex)
144-
{
145-
ice::mem_destruct_n_at(_data, _count);
146-
}
147-
148-
_allocator->deallocate(memory_view());
149-
}
150-
151149
template<typename Type, ice::ContainerLogic Logic>
152150
inline Array<Type, Logic>::Array(
153151
ice::Allocator& alloc,
154152
ice::Span<Type const> values
155-
) noexcept
156-
requires std::copy_constructible<Type>
157-
: _allocator{ &alloc }
153+
) noexcept requires std::copy_constructible<Type>
154+
: _allocator{ &alloc }
158155
, _capacity{ 0 }
159156
, _count{ 0 }
160157
, _data{ nullptr }
@@ -228,18 +225,6 @@ namespace ice
228225
return *this;
229226
}
230227

231-
template<typename Type, ice::ContainerLogic Logic>
232-
inline Array<Type, Logic>::operator ice::Span<Type>() noexcept
233-
{
234-
return Span{ _data, _count };
235-
}
236-
237-
template<typename Type, ice::ContainerLogic Logic>
238-
inline Array<Type, Logic>::operator ice::Span<Type const>() const noexcept
239-
{
240-
return Span{ _data, _count };
241-
}
242-
243228
template<typename Type, ice::ContainerLogic Logic>
244229
inline constexpr void ice::Array<Type, Logic>::set_capacity(ice::ncount new_capacity) noexcept
245230
{
@@ -349,8 +334,7 @@ namespace ice
349334

350335
template<typename Type, ice::ContainerLogic Logic>
351336
template<ice::concepts::IterableContainer ContainerT>
352-
requires (std::convertible_to<ice::container::ValueType<ContainerT>, Type>
353-
&& std::is_constructible_v<Type, ice::container::ValueType<ContainerT>>)
337+
requires (ice::concepts::CompatibleContainer<Type, ContainerT>)
354338
inline void ice::Array<Type, Logic>::push_back(ContainerT const& other) noexcept
355339
{
356340
ice::ncount const current_size = size();
@@ -408,5 +392,17 @@ namespace ice
408392
};
409393
}
410394

395+
template<typename Type, ice::ContainerLogic Logic>
396+
inline Array<Type, Logic>::operator ice::Span<Type>() noexcept
397+
{
398+
return Span{ _data, _count };
399+
}
400+
401+
template<typename Type, ice::ContainerLogic Logic>
402+
inline Array<Type, Logic>::operator ice::Span<Type const>() const noexcept
403+
{
404+
return Span{ _data, _count };
405+
}
406+
411407

412408
} // namespace ice

source/code/core/collections/public/ice/container/basic_container.hxx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,31 @@ namespace ice::container
1919
}
2020

2121
template<ice::concepts::Container Self>
22+
requires ice::concepts::ContiguousContainer<Self> || ice::concepts::IterableContainer<Self>
2223
constexpr auto first(this Self&& self) noexcept -> ice::container::ValueRef<Self>
2324
{
24-
return self.data()[0];
25+
if constexpr (ice::concepts::ContiguousContainer<Self>)
26+
{
27+
return self.data()[0];
28+
}
29+
else
30+
{
31+
return *self.begin();
32+
}
2533
}
2634

2735
template<ice::concepts::Container Self>
36+
requires ice::concepts::ContiguousContainer<Self> || ice::concepts::ReverseIterableContainer<Self>
2837
constexpr auto last(this Self&& self) noexcept -> ice::container::ValueRef<Self>
2938
{
30-
return self.data()[self.size() - 1];
39+
if constexpr (ice::concepts::ContiguousContainer<Self>)
40+
{
41+
return self.data()[self.size() - 1];
42+
}
43+
else
44+
{
45+
return *self.rbegin();
46+
}
3147
}
3248
};
3349

source/code/core/collections/public/ice/container/container_concepts.hxx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ namespace ice::concepts
2020
template<typename T>
2121
concept Container = ContainerType<T> && requires(T t) {
2222
{ t.size() } -> std::convertible_to<ice::ncount>;
23-
{ t.data() } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType const*>;
2423
};
2524

2625
template<typename T>
2726
concept ResizableContainer = Container<T> && requires(T t, ice::ncount size) {
28-
{ t.data() } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType*>;
27+
// { t.data() } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType*>;
2928
{ t.capacity() } -> std::convertible_to<ice::ncount>;
3029
{ t.set_capacity(size) } -> std::convertible_to<void>;
3130
{ t.resize(size) } -> std::convertible_to<void>;
@@ -37,9 +36,15 @@ namespace ice::concepts
3736
template<typename T>
3837
concept ContiguousContainer = Container<T> && requires(T t) {
3938
std::is_same_v<typename std::remove_reference_t<T>::ContainerTag, ContiguousContainerTag>;
39+
{ t.data() } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType const*>;
4040
{ t.data_view() } -> std::convertible_to<ice::Data>;
4141
};
4242

43+
template<typename T>
44+
concept ContiguousResizableContainer = ResizableContainer<T> && ContiguousContainer<T> && requires(T t) {
45+
{ t.memory_view() } -> std::convertible_to<ice::Memory>;
46+
};
47+
4348
template<typename T>
4449
concept TrivialContainerLogic = ContainerType<T>
4550
&& TrivialContainerLogicAllowed<typename std::remove_reference_t<T>::ValueType>;
@@ -88,6 +93,9 @@ namespace ice::container
8893
template<ice::concepts::ContainerType ContainerT>
8994
using ValueRef = ValueType<ContainerT>&;
9095

96+
template<ice::concepts::ContainerType ContainerT>
97+
using ValueRVal = ValueType<ContainerT>&&;
98+
9199
template<ice::concepts::ContainerType ContainerT>
92100
using ValuePtr = ValueType<ContainerT>*;
93101

@@ -108,10 +116,23 @@ namespace ice::container
108116
namespace ice::concepts
109117
{
110118

119+
template<typename TargetT, typename SourceContainerT>
120+
concept CompatibleContainer = std::convertible_to<
121+
ice::container::ValueType<SourceContainerT>,
122+
TargetT
123+
>;// && std::is_constructible_v<Type, ice::container::ValueType<ContainerT>>)
124+
125+
111126
template<typename T>
112-
concept IterableContainer = ContainerType<T> && requires(T t) {
127+
concept IterableContainer = ice::concepts::Container<T> && requires(T t) {
113128
{ t.begin() } -> std::convertible_to<ice::container::Iterator<T>>;
114129
{ t.end() } -> std::convertible_to<ice::container::Iterator<T>>;
115130
};
116131

132+
template<typename T>
133+
concept ReverseIterableContainer = requires(T t) {
134+
{ t.rbegin() } -> std::convertible_to<ice::container::ReverseIterator<T>>;
135+
{ t.rend() } -> std::convertible_to<ice::container::ReverseIterator<T>>;
136+
};
137+
117138
} // namespace ice::concepts

source/code/core/collections/public/ice/container/contiguous_container.hxx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ice::container
1010
struct ContiguousContainer : ice::container::BasicContainer
1111
{
1212
// Accessing Data with Spans
13-
template<ice::concepts::Container Self>
13+
template<ice::concepts::ContiguousContainer Self>
1414
constexpr auto subspan(
1515
this Self&& self,
1616
ice::nindex from,
@@ -23,7 +23,7 @@ namespace ice::container
2323
return { self.data() + from_start.native(), count.min_value_or(remaining_count, remaining_count)};
2424
}
2525

26-
template<ice::concepts::Container Self>
26+
template<ice::concepts::ContiguousContainer Self>
2727
constexpr auto subspan(
2828
this Self&& self,
2929
ice::ref32 refval
@@ -32,7 +32,7 @@ namespace ice::container
3232
return self.subspan(refval.offset, refval.size);
3333
}
3434

35-
template<ice::concepts::Container Self>
35+
template<ice::concepts::ContiguousContainer Self>
3636
constexpr auto headspan(
3737
this Self&& self,
3838
ice::ncount count = 1
@@ -42,7 +42,7 @@ namespace ice::container
4242
return { self.data(), count.min_value_or(self.size(), 0_count) };
4343
}
4444

45-
template<ice::concepts::Container Self>
45+
template<ice::concepts::ContiguousContainer Self>
4646
constexpr auto tailspan(
4747
this Self&& self,
4848
ice::nindex offset = 1
@@ -56,45 +56,45 @@ namespace ice::container
5656
}
5757

5858
// Iteration interface
59-
template<ice::concepts::Container Self>
59+
template<ice::concepts::ContiguousContainer Self>
6060
constexpr auto begin(this Self&& self) noexcept -> ice::container::Iterator<Self>
6161
{
6262
return { self.data() };
6363
}
6464

65-
template<ice::concepts::Container Self>
65+
template<ice::concepts::ContiguousContainer Self>
6666
constexpr auto end(this Self&& self) noexcept -> ice::container::Iterator<Self>
6767
{
6868
return { self.data() + self.size() };
6969
}
7070

71-
template<ice::concepts::Container Self>
71+
template<ice::concepts::ContiguousContainer Self>
7272
constexpr auto rbegin(this Self&& self) noexcept -> ice::container::ReverseIterator<Self>
7373
{
7474
return ice::container::ReverseIterator<Self>{ self.data() + self.size() };
7575
}
7676

77-
template<ice::concepts::Container Self>
77+
template<ice::concepts::ContiguousContainer Self>
7878
constexpr auto rend(this Self&& self) noexcept -> ice::container::ReverseIterator<Self>
7979
{
8080
return ice::container::ReverseIterator<Self>{ self.data() };
8181
}
8282

8383
// Operators
84-
template<ice::concepts::Container Self>
84+
template<ice::concepts::ContiguousContainer Self>
8585
constexpr auto operator[](this Self&& self, ice::nindex index) noexcept -> ice::container::ValueRef<Self>
8686
{
8787
return self.data()[index];
8888
}
8989

9090
// Data API
91-
template<ice::concepts::Container Self>
91+
template<ice::concepts::ContiguousContainer Self>
9292
inline auto meminfo(this Self const& self) noexcept -> ice::meminfo
9393
{
9494
return ice::meminfo_of<typename Self::ValueType> * self.size();
9595
}
9696

97-
template<ice::concepts::ResizableContainer Self> requires (ice::concepts::TrivialContainerLogic<Self>)
97+
template<ice::concepts::ContiguousResizableContainer Self> requires (ice::concepts::TrivialContainerLogic<Self>)
9898
inline auto memset(this Self const& self, ice::u8 value) noexcept -> ice::Memory
9999
{
100100
ice::Memory mem{ self.data(), self.size(), ice::align_of<ice::container::ValueType<Self>> };

0 commit comments

Comments
 (0)