aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi/shmem.hpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-27 13:17:26 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-27 13:18:45 +0300
commit0c62070b24273e565cce112ab061df6665d3ae8c (patch)
treea9a36ef593871daef57986fbfbbfb44de8c1116d /include/winapi/shmem.hpp
parentBoost.Test is broken in 1.62 (diff)
downloadwinapi-common-0c62070b24273e565cce112ab061df6665d3ae8c.tar.gz
winapi-common-0c62070b24273e565cce112ab061df6665d3ae8c.zip
code style
Don't use brace initialization in constructors, VS 2013 doesn't like that.
Diffstat (limited to '')
-rw-r--r--include/winapi/shmem.hpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/include/winapi/shmem.hpp b/include/winapi/shmem.hpp
index 0fb2b76..f2ce33e 100644
--- a/include/winapi/shmem.hpp
+++ b/include/winapi/shmem.hpp
@@ -38,7 +38,7 @@ private:
SharedMemory() = default;
- SharedMemory(Handle&& handle, void* addr) : m_handle{std::move(handle)}, m_addr{addr} {}
+ SharedMemory(Handle&& handle, void* addr) : m_handle(std::move(handle)), m_addr(addr) {}
Handle m_handle;
std::unique_ptr<void, Unmap> m_addr;
@@ -67,26 +67,28 @@ public:
}
SharedObject(SharedObject&& other) BOOST_NOEXCEPT_OR_NOTHROW
- : m_shmem{std::move(other.m_shmem)},
- m_destruct{other.m_destruct} {}
+ : m_shmem(std::move(other.m_shmem)),
+ m_destruct(other.m_destruct) {}
SharedObject& operator=(SharedObject other) BOOST_NOEXCEPT_OR_NOTHROW {
swap(other);
return *this;
}
- ~SharedObject() {
- if (m_destruct && ptr()) {
- ptr()->~T();
- }
- }
-
void swap(SharedObject& other) BOOST_NOEXCEPT_OR_NOTHROW {
using std::swap;
swap(m_shmem, other.m_shmem);
swap(m_destruct, other.m_destruct);
}
+ SharedObject(const SharedObject&) = delete;
+
+ ~SharedObject() {
+ if (m_destruct && ptr()) {
+ ptr()->~T();
+ }
+ }
+
T* ptr() const { return reinterpret_cast<T*>(m_shmem.ptr()); }
T& get() const { return *ptr(); }
@@ -94,13 +96,11 @@ public:
T& operator*() const { return get(); }
private:
- explicit SharedObject(SharedMemory&& shmem) : m_shmem{std::move(shmem)} {}
+ explicit SharedObject(SharedMemory&& shmem) : m_shmem(std::move(shmem)) {}
SharedMemory m_shmem;
// Destruct only once, no matter the number of mappings.
bool m_destruct = false;
-
- SharedObject(const SharedObject&) = delete;
};
template <typename T>
@@ -117,9 +117,4 @@ inline void swap(winapi::SharedMemory& a, winapi::SharedMemory& b) BOOST_NOEXCEP
a.swap(b);
}
-template <typename T>
-inline void swap(winapi::SharedObject<T>& a, winapi::SharedObject<T>& b) BOOST_NOEXCEPT_OR_NOTHROW {
- a.swap(b);
-}
-
} // namespace std