Skip to content

Commit

Permalink
Updated README and added fix for GCC/Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
WillisMedwell committed Feb 2, 2024
1 parent 805d58a commit 74f4725
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
47 changes: 19 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,22 @@ Utily::StaticVector<int, 10> s_vector{1, 2, 3, 4};
A vector with no compile time enfored type. Access is checked in debug mode at runtime using Reflection.
Useful for on the fly composing of types.
```c++
auto vector = Utily::TypeErasedVector {};
vector.set_underlying_type<float>();
// cannot resize or push back if the underlying_type is not set.
auto vector = Utily::TypeErasedVector {};
vector.set_underlying_type<float>();
// these operations will throw in debug mode.
vector.emplace_back<int>(1);
vector.emplace_back<double>(1);
// these operations will assert false in debug mode.
vector.emplace_back<int>(1);
vector.emplace_back<double>(1);
vector.push_back<float>(0.0f);
vector.emplace_back<float>(1.0f);
// these will be valid.
vector.push_back<float>(0.0f);
vector.emplace_back<float>(1.0f);
// as_span<T> can throw if T != Underlying
for (float& v : vector.as_span<float>()) {
std::cout << v << ' ';
}
// as_span<T> will assert if T != Underlying.
for (float& v : vector.as_span<float>()) {
std::cout << v << ' ';
}
```

---
Expand Down Expand Up @@ -204,30 +206,19 @@ Simd optimised operations for supported algorithms. Mostly char searching at the
const auto DELIMS = std::string_view { "azxy" };
const auto STRING = std::string { "hello world! This is a sentenze" };

auto iter1 = Utily::Simd::find(STRING.begin(), STRING.end(), DELIMS.front());

auto iter2 = Utily::Simd::find_first_of(
```
```C++
auto iter = Utily::Simd::find(STRING.begin(), STRING.end(), DELIMS.front());
```
```C++
auto iter = Utily::Simd::find_first_of(
STRING.begin(), STRING.end(),
DELIMS.begin(), DELIMS.end()
);

```

---

</details>
<details><summary><b>Utily::Concepts</b></summary>
Just a collection of [concepts](https://en.cppreference.com/w/cpp/concepts) to restrict/narrow types for templated functions ontop of the STL.
---
</details>
<details><summary><b>Utily::Split</b></summary>

Subdividing ranges ('splitting') is so common and there's many slightly different ways we need to do it. Below are the iterator classes for each type of split.
Expand Down
2 changes: 1 addition & 1 deletion include/Utily/TypeErasedVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Utily {
#ifdef _MSC_VER
_aligned_free(_data);
#else
free(data);
free(_data);
#endif
_data = nullptr;
}
Expand Down
5 changes: 4 additions & 1 deletion test/UnitTypeErasedVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
TEST(TypeErasedVector, Constructor) {
{
auto vector = Utily::TypeErasedVector {};
#ifndef NDEBUG
EXPECT_DEBUG_DEATH(vector.emplace_back<int>(1), "");

#endif
vector.set_underlying_type<float>();
EXPECT_EQ(vector.size(), 0);
EXPECT_EQ(vector.size_bytes(), 0);
Expand Down Expand Up @@ -38,8 +39,10 @@ TEST(TypeErasedVector, push_back) {
EXPECT_EQ(vector.size_bytes(), 0);
EXPECT_EQ(vector.capacity(), 0);

#ifndef NDEBUG
EXPECT_DEBUG_DEATH(vector.emplace_back<int>(1), "");
EXPECT_DEBUG_DEATH(vector.emplace_back<double>(1), "");
#endif

vector.push_back<float>(0.0f);
vector.push_back<float>(1.0f);
Expand Down

0 comments on commit 74f4725

Please sign in to comment.