Skip to content

Commit d0ae2f0

Browse files
committed
#ICE-205 State In Progress
Proof of concept on defining container operations using C++ concepts and mixin types.
1 parent a2f17f4 commit d0ae2f0

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
#include <ice/types/ncount.hxx>
3+
#include <ice/types/nindex.hxx>
4+
5+
namespace ice::concepts
6+
{
7+
8+
template<typename T>
9+
concept ContiguousContainer = requires(T t) {
10+
{ t.size() } -> std::convertible_to<ice::ncount>;
11+
{ t.data() } -> std::convertible_to<typename T::ValueType const*>;
12+
};
13+
14+
} // namespace ice::concepts
15+
16+
namespace ice::container
17+
{
18+
19+
template<typename ContainerT>
20+
using ValueRef = ice::const_correct_t<std::remove_reference_t<ContainerT>, typename ContainerT::ValueType>&;
21+
22+
template<typename ContainerT>
23+
using ValuePtr = ice::const_correct_t<std::remove_reference_t<ContainerT>, typename ContainerT::ValueType>*;
24+
25+
} // namespace ice::container
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <ice/container/container_concepts.hxx>
3+
4+
namespace ice::container
5+
{
6+
7+
struct ContiguousContainer
8+
{
9+
template<ice::concepts::ContiguousContainer Self>
10+
constexpr auto front(this Self& self) noexcept -> ice::container::ValueRef<Self>
11+
{
12+
return self.data()[0];
13+
}
14+
};
15+
16+
} // namespace ice::container

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33

44
#pragma once
55
#include <ice/mem_allocator.hxx>
6+
#include <ice/container/contiguous_container.hxx>
7+
68
#include <ice/container_logic.hxx>
79
#include <ice/string_types.hxx>
810
#include <ice/span.hxx>
911
#include <array>
1012

1113
namespace ice
1214
{
15+
struct Test : ice::container::ContiguousContainer
16+
{
17+
using ValueType = int;
18+
19+
int foo[4];
20+
21+
template<typename Self>
22+
constexpr auto data(this Self& self) noexcept -> ice::const_correct_t<Self, ValueType>* { return self.foo; }
23+
constexpr ncount size() const noexcept { return 4; }
24+
};
1325

1426
//! \brief A simple contaier storing items in contignous memory.
1527
//!

0 commit comments

Comments
 (0)