Switch pimpl away from std::unique_ptr due to msvc awfulness
This commit is contained in:
parent
c6021fe8f5
commit
3cb7ef4ec5
@ -9,8 +9,9 @@
|
|||||||
|
|
||||||
namespace cpptrace {
|
namespace cpptrace {
|
||||||
class CPPTRACE_EXPORT formatter {
|
class CPPTRACE_EXPORT formatter {
|
||||||
class CPPTRACE_EXPORT impl;
|
class impl;
|
||||||
std::unique_ptr<impl> pimpl;
|
// can't be a std::unique_ptr due to msvc awfulness with dllimport/dllexport and https://stackoverflow.com/q/4145605/15675011
|
||||||
|
impl* pimpl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
formatter();
|
formatter();
|
||||||
|
|||||||
@ -212,14 +212,25 @@ namespace cpptrace {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
formatter::formatter() : pimpl(std::unique_ptr<impl>(new impl)) {}
|
formatter::formatter() : pimpl(new impl) {}
|
||||||
formatter::~formatter() = default;
|
formatter::~formatter() {
|
||||||
|
delete pimpl;
|
||||||
|
}
|
||||||
|
|
||||||
formatter::formatter(formatter&&) = default;
|
formatter::formatter(formatter&& other) : pimpl(detail::exchange(other.pimpl, nullptr)) {}
|
||||||
formatter::formatter(const formatter& other) : pimpl(std::unique_ptr<impl>(new impl(*other.pimpl))) {}
|
formatter::formatter(const formatter& other) : pimpl(new impl(*other.pimpl)) {}
|
||||||
formatter& formatter::operator=(formatter&&) = default;
|
formatter& formatter::operator=(formatter&& other) {
|
||||||
|
if(pimpl) {
|
||||||
|
delete pimpl;
|
||||||
|
}
|
||||||
|
pimpl = detail::exchange(other.pimpl, nullptr);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
formatter& formatter::operator=(const formatter& other) {
|
formatter& formatter::operator=(const formatter& other) {
|
||||||
pimpl = std::unique_ptr<impl>(new impl(*other.pimpl));
|
if(pimpl) {
|
||||||
|
delete pimpl;
|
||||||
|
}
|
||||||
|
pimpl = new impl(*other.pimpl);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -189,6 +189,13 @@ namespace detail {
|
|||||||
return static_cast<U>(v);
|
return static_cast<U>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename U = T>
|
||||||
|
T exchange(T& obj, U&& value) {
|
||||||
|
T old = std::move(obj);
|
||||||
|
obj = std::forward<U>(value);
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
struct monostate {};
|
struct monostate {};
|
||||||
|
|
||||||
// TODO: Rework some stuff here. Not sure deleters should be optional or moved.
|
// TODO: Rework some stuff here. Not sure deleters should be optional or moved.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user