Skip to content

Commit 8212b02

Browse files
committed
Code cleaning
1 parent 2529c7c commit 8212b02

18 files changed

Lines changed: 65 additions & 64 deletions

modules/Container/DependencyGraph.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export namespace CppUtils::Container
4343
std::erase(node.dependencies, key);
4444
}
4545

46-
[[nodiscard]] inline auto operator[](this auto&& self, const Key& key) -> decltype(auto)
46+
[[nodiscard]] inline auto operator[](this auto&& self [[lifetimebound]], const Key& key) -> decltype(auto)
4747
{
4848
if constexpr (std::is_const_v<std::remove_reference_t<decltype(self)>>)
4949
return (self.nodes.at(key).value);
@@ -61,7 +61,7 @@ export namespace CppUtils::Container
6161
std::erase(nodes[key].dependencies, dependency);
6262
}
6363

64-
[[nodiscard]] inline auto getDependencies(this auto&& self, const Key& key) -> decltype(auto)
64+
[[nodiscard]] inline auto getDependencies(this auto&& self [[lifetimebound]], const Key& key) -> decltype(auto)
6565
{
6666
if constexpr (std::is_const_v<std::remove_reference_t<decltype(self)>>)
6767
return (self.nodes.at(key).dependencies);

modules/Container/MeshNetwork.mpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export namespace CppUtils::Container
143143
{}
144144

145145
private:
146-
[[nodiscard]] auto getVectorAccessor(this auto&& self) -> auto&
146+
[[nodiscard]] auto getVectorAccessor(this auto&& self [[lifetimebound]]) -> auto&
147147
{
148148
if (not self.m_vectorAccessor) [[unlikely]]
149149
{
@@ -316,8 +316,8 @@ export namespace CppUtils::Container
316316

317317
static_assert(std::random_access_iterator<Iterator>);
318318

319-
[[nodiscard]] auto begin() const { return Iterator{this, 0uz}; }
320-
[[nodiscard]] auto end() const { return Iterator{this, size()}; }
319+
[[nodiscard]] auto begin() const [[lifetimebound]] { return Iterator{this, 0uz}; }
320+
[[nodiscard]] auto end() const [[lifetimebound]] { return Iterator{this, size()}; }
321321

322322
private:
323323
MeshNodePtr m_parent;
@@ -415,12 +415,12 @@ export namespace CppUtils::Container
415415
return m_node->sharedAccess()->getDistanceFromRoot();
416416
}
417417

418-
[[nodiscard]] auto operator->(this auto&& self)
418+
[[nodiscard]] auto operator->(this auto&& self [[lifetimebound]])
419419
{
420420
return std::addressof(std::forward_like<decltype(self)>(*self.m_node));
421421
}
422422

423-
[[nodiscard]] auto operator*(this auto&& self) -> decltype(auto)
423+
[[nodiscard]] auto operator*(this auto&& self [[lifetimebound]]) -> decltype(auto)
424424
{
425425
return std::forward_like<decltype(self)>(*self.m_node);
426426
}

modules/Container/Vec2.mpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ export namespace CppUtils::Container
2020
m_values{static_cast<T>(args)...}
2121
{}
2222

23-
[[nodiscard]] inline constexpr auto operator[](this auto&& self, std::size_t axis) noexcept -> decltype(auto)
23+
[[nodiscard]] inline constexpr auto operator[](this auto&& self [[lifetimebound]], std::size_t axis) noexcept -> decltype(auto)
2424
{
2525
assert(axis < 2);
2626
return self.m_values[axis];
2727
}
2828

29-
[[nodiscard]] inline constexpr auto x(this auto&& self) noexcept -> decltype(auto) { return self[0]; }
30-
[[nodiscard]] inline constexpr auto y(this auto&& self) noexcept -> decltype(auto) { return self[1]; }
31-
[[nodiscard]] inline constexpr auto width(this auto&& self) noexcept -> decltype(auto) { return self[0]; }
32-
[[nodiscard]] inline constexpr auto height(this auto&& self) noexcept -> decltype(auto) { return self[1]; }
29+
[[nodiscard]] inline constexpr auto x(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[0]; }
30+
[[nodiscard]] inline constexpr auto y(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[1]; }
31+
[[nodiscard]] inline constexpr auto width(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[0]; }
32+
[[nodiscard]] inline constexpr auto height(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[1]; }
3333

3434
[[nodiscard]] friend inline constexpr auto operator==(const Vec2& lhs, const Vec2& rhs) noexcept -> bool
3535
{

modules/Container/Vec3.mpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ export namespace CppUtils::Container
2020
m_values{static_cast<T>(args)...}
2121
{}
2222

23-
[[nodiscard]] inline constexpr auto operator[](this auto&& self, std::size_t axis) noexcept -> decltype(auto)
23+
[[nodiscard]] inline constexpr auto operator[](this auto&& self [[lifetimebound]], std::size_t axis) noexcept -> decltype(auto)
2424
{
2525
assert(axis < 3);
2626
return self.m_values[axis];
2727
}
2828

29-
[[nodiscard]] inline constexpr auto x(this auto&& self) noexcept -> decltype(auto) { return self[0]; }
30-
[[nodiscard]] inline constexpr auto y(this auto&& self) noexcept -> decltype(auto) { return self[1]; }
31-
[[nodiscard]] inline constexpr auto z(this auto&& self) noexcept -> decltype(auto) { return self[2]; }
32-
[[nodiscard]] inline constexpr auto width(this auto&& self) noexcept -> decltype(auto) { return self[0]; }
33-
[[nodiscard]] inline constexpr auto height(this auto&& self) noexcept -> decltype(auto) { return self[1]; }
34-
[[nodiscard]] inline constexpr auto depth(this auto&& self) noexcept -> decltype(auto) { return self[2]; }
29+
[[nodiscard]] inline constexpr auto x(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[0]; }
30+
[[nodiscard]] inline constexpr auto y(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[1]; }
31+
[[nodiscard]] inline constexpr auto z(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[2]; }
32+
[[nodiscard]] inline constexpr auto width(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[0]; }
33+
[[nodiscard]] inline constexpr auto height(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[1]; }
34+
[[nodiscard]] inline constexpr auto depth(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto) { return self[2]; }
3535

3636
[[nodiscard]] friend inline constexpr auto operator==(const Vec3& lhs, const Vec3& rhs) noexcept -> bool
3737
{

modules/Execution/ScopeGuard.mpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export namespace CppUtils::Execution
3737
}
3838

3939
private:
40-
Function m_onExit;
40+
[[no_unique_address]] Function m_onExit;
4141
bool m_active = true;
4242
};
4343

modules/FileSystem/File.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ export namespace CppUtils::FileSystem
5454
std::size_t blockSize = 4'096) -> std::expected<void, Error>
5555
{
5656
auto file = std::ifstream{filePath, std::ios::binary};
57-
if (not file.is_open())
57+
if (not file.is_open()) [[unlikely]]
5858
return std::unexpected{Error{Error::Type::OpenFailed, "Failed to open file"}};
5959

6060
for (auto buffer = std::vector<char>(blockSize); file.good();)
6161
{
6262
file.read(std::data(buffer), static_cast<std::streamsize>(blockSize));
6363

64-
if (file.bad())
64+
if (file.bad()) [[unlikely]]
6565
return std::unexpected{Error{Error::Type::ReadFailed, "Hardware read error"}};
6666

6767
const auto bytesRead = static_cast<std::size_t>(file.gcount());

modules/Language/JSON/Mapping.mpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ export namespace CppUtils::Language::JSON
7676
return std::nullopt;
7777
}
7878

79-
[[nodiscard]] inline auto operator[](std::string_view key) const -> const Value&;
80-
[[nodiscard]] inline auto operator[](std::size_t index) const -> const Value&;
81-
8279
[[nodiscard]] constexpr auto operator==(const Value&) const -> bool = default;
8380

8481
[[nodiscard]] inline operator std::string() const
@@ -88,6 +85,9 @@ export namespace CppUtils::Language::JSON
8885
return result;
8986
}
9087

88+
[[nodiscard]] inline auto operator[](this auto&& self [[lifetimebound]], std::string_view key) -> const Value&;
89+
[[nodiscard]] inline auto operator[](this auto&& self [[lifetimebound]], std::size_t index) -> const Value&;
90+
9191
template<std::output_iterator<char> Iterator>
9292
inline auto dump(Iterator out) const -> Iterator
9393
{
@@ -137,9 +137,9 @@ export namespace CppUtils::Language::JSON
137137

138138
inline constinit const auto nullValue = Value{};
139139

140-
[[nodiscard]] inline auto Value::operator[](std::string_view key) const -> const Value&
140+
[[nodiscard]] inline auto Value::operator[](this auto&& self [[lifetimebound]], std::string_view key) -> const Value&
141141
{
142-
if (auto object = getIf<Object>())
142+
if (auto object = self.template getIf<Object>())
143143
{
144144
const auto& objectRef = object->get();
145145
if (auto it = objectRef.find(key); it != std::end(objectRef))
@@ -148,9 +148,9 @@ export namespace CppUtils::Language::JSON
148148
return nullValue;
149149
}
150150

151-
[[nodiscard]] inline auto Value::operator[](std::size_t index) const -> const Value&
151+
[[nodiscard]] inline auto Value::operator[](this auto&& self [[lifetimebound]], std::size_t index) -> const Value&
152152
{
153-
if (auto array = getIf<Array>())
153+
if (auto array = self.template getIf<Array>())
154154
{
155155
const auto& arrayRef = array->get();
156156
if (index < std::size(arrayRef))

modules/Log/ChronoLogger.mpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export namespace CppUtils::Log
3737
}
3838

3939
private:
40-
Callback m_callback;
40+
[[no_unique_address]] Callback m_callback;
4141
bool m_enabled;
4242
Chrono::Chronometer<> m_chrono;
4343
};

modules/Math/Utility.mpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export namespace CppUtils::Math
3030
template<std::floating_point Float>
3131
[[nodiscard]] inline constexpr auto isEqual(Float lhs, Float rhs, Float epsilon = std::numeric_limits<Float>::epsilon()) noexcept -> bool
3232
{
33+
[[assume(epsilon > 0)]];
3334
auto difference = absolute(lhs - rhs);
3435
auto maximum = std::max(absolute(lhs), absolute(rhs));
3536
if (maximum >= Float{1})

modules/String/Cursor.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export namespace CppUtils::String
1212
Source source;
1313
std::size_t position = 0;
1414

15-
[[nodiscard]] inline auto getCurrent() -> const auto&
15+
[[nodiscard]] inline auto getCurrent(this auto&& self [[lifetimebound]]) -> decltype(auto)
1616
{
17-
return source[position];
17+
return self.source[self.position];
1818
}
1919
};
2020
}

0 commit comments

Comments
 (0)