aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 16:42:21 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 16:42:21 +0100
commit9eff2e24fa4cf0ffad2b47cc922a6558bc1a9fa1 (patch)
treee673cba5f221523d37f51b67a155abfc0c415eb3 /src/crepe/util
parentf7d70abf3fee5933034d93f594f898849c5273ad (diff)
`make format`
Diffstat (limited to 'src/crepe/util')
-rw-r--r--src/crepe/util/Private.cpp17
-rw-r--r--src/crepe/util/Private.h5
-rw-r--r--src/crepe/util/Private.hpp18
3 files changed, 15 insertions, 25 deletions
diff --git a/src/crepe/util/Private.cpp b/src/crepe/util/Private.cpp
index cb4cb5b..262620d 100644
--- a/src/crepe/util/Private.cpp
+++ b/src/crepe/util/Private.cpp
@@ -2,18 +2,14 @@
using namespace crepe;
-bool Private::empty() const noexcept {
- return this->instance == nullptr;
-}
+bool Private::empty() const noexcept { return this->instance == nullptr; }
Private::~Private() {
if (this->instance == nullptr) return;
this->destructor(this->instance);
}
-Private::Private(Private && other) {
- *this = std::move(other);
-}
+Private::Private(Private && other) { *this = std::move(other); }
Private & Private::operator=(Private && other) {
// TODO: ideally this function checks for self-assignment
@@ -22,13 +18,10 @@ Private & Private::operator=(Private && other) {
this->type = other.type;
other.instance = nullptr;
- other.destructor = [](void*){};
-
- return *this;
-}
+ other.destructor = [](void *) {};
-Private::Private(const Private & other) { }
-Private & Private::operator=(const Private & other) {
return *this;
}
+Private::Private(const Private & other) {}
+Private & Private::operator=(const Private & other) { return *this; }
diff --git a/src/crepe/util/Private.h b/src/crepe/util/Private.h
index 6dd28bb..62a2e1a 100644
--- a/src/crepe/util/Private.h
+++ b/src/crepe/util/Private.h
@@ -1,7 +1,7 @@
#pragma once
-#include <typeindex>
#include <functional>
+#include <typeindex>
namespace crepe {
@@ -28,7 +28,6 @@ private:
void * instance = nullptr;
};
-}
+} // namespace crepe
#include "Private.hpp"
-
diff --git a/src/crepe/util/Private.hpp b/src/crepe/util/Private.hpp
index d6ab23f..3a87a9f 100644
--- a/src/crepe/util/Private.hpp
+++ b/src/crepe/util/Private.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include <stdexcept>
#include <format>
+#include <stdexcept>
#include "Private.h"
@@ -11,10 +11,8 @@ template <typename T, typename... Args>
T & Private::set(Args &&... args) {
if (!this->empty()) this->destructor(this->instance);
T * instance = new T(std::forward<Args>(args)...);
- this->instance = static_cast<void*>(instance);
- this->destructor = [](void * instance) {
- delete static_cast<T*>(instance);
- };
+ this->instance = static_cast<void *>(instance);
+ this->destructor = [](void * instance) { delete static_cast<T *>(instance); };
this->type = typeid(T);
return *instance;
}
@@ -22,12 +20,12 @@ T & Private::set(Args &&... args) {
template <typename T>
T & Private::get() {
using namespace std;
- if (this->empty())
- throw out_of_range("Private: get() called on empty object");
+ if (this->empty()) throw out_of_range("Private: get() called on empty object");
type_index requested_type = typeid(T);
if (this->type != requested_type)
- throw logic_error(format("Private: get() called with [T = {}] (actual is [T = {}])", requested_type.name(), this->type.name()));
- return *static_cast<T*>(this->instance);
+ throw logic_error(format("Private: get() called with [T = {}] (actual is [T = {}])",
+ requested_type.name(), this->type.name()));
+ return *static_cast<T *>(this->instance);
}
-}
+} // namespace crepe