HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
utils.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <atomic>
8#include <utility>
9
19#define hi_get_overloaded_macro2(_1, _2, name, ...) name
20
21namespace hi::inline v1 {
22
26template<typename T, typename U>
27[[nodiscard]] bool compare_store(T &lhs, U &&rhs) noexcept
28{
29 if (lhs != rhs) {
30 lhs = std::forward<U>(rhs);
31 return true;
32 } else {
33 return false;
34 }
35}
36
42template<typename T, typename U>
43[[nodiscard]] bool compare_store(std::atomic<T> &lhs, U &&rhs) noexcept
44{
45 return lhs.exchange(rhs, std::memory_order::relaxed) != rhs;
46}
47
48} // namespace hi::inline v1