Merge remote-tracking branch 'origin/master' into feature/allow_input.text_from_hotkeys

This commit is contained in:
Rasmus Karlsson 2024-01-26 22:43:23 +01:00
commit c98a0cf460
2 changed files with 68 additions and 1 deletions

View file

@ -134,6 +134,7 @@
- Dev: Added benchmark for parsing and building recent messages. (#5071)
- Dev: Boost is depended on as a header-only library when using conan. (#5107)
- Dev: Added signal to invalidate paint buffers of channel views without forcing a relayout. (#5123)
- Dev: Specialize `Atomic<std::shared_ptr<T>>` if underlying standard library supports it. (#5133)
## 2.4.6

View file

@ -1,5 +1,7 @@
#pragma once
#include <atomic>
#include <memory>
#include <mutex>
namespace chatterino {
@ -9,9 +11,10 @@ class Atomic
{
public:
Atomic() = default;
~Atomic() = default;
Atomic(T &&val)
: value_(val)
: value_(std::move(val))
{
}
@ -47,4 +50,67 @@ private:
T value_;
};
#if defined(__cpp_lib_atomic_shared_ptr) && defined(__cpp_concepts)
template <typename T>
class Atomic<std::shared_ptr<T>>
{
// Atomic<std::shared_ptr<T>> must be instantated with a const T
};
template <typename T>
requires std::is_const_v<T>
class Atomic<std::shared_ptr<T>>
{
public:
Atomic() = default;
~Atomic() = default;
Atomic(T &&val)
: value_(std::make_shared<T>(std::move(val)))
{
}
Atomic(std::shared_ptr<T> &&val)
: value_(std::move(val))
{
}
Atomic(const Atomic &) = delete;
Atomic &operator=(const Atomic &) = delete;
Atomic(Atomic &&) = delete;
Atomic &operator=(Atomic &&) = delete;
std::shared_ptr<T> get() const
{
return this->value_.load();
}
void set(const T &val)
{
this->value_.store(std::make_shared<T>(val));
}
void set(T &&val)
{
this->value_.store(std::make_shared<T>(std::move(val)));
}
void set(const std::shared_ptr<T> &val)
{
this->value_.store(val);
}
void set(std::shared_ptr<T> &&val)
{
this->value_.store(std::move(val));
}
private:
std::atomic<std::shared_ptr<T>> value_;
};
#endif
} // namespace chatterino