Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections constructor #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion safe_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,18 @@ namespace sf {
template<typename mutex_type> friend class std::shared_lock; // C++14
#endif

private:

safe_ptr(std::shared_ptr<T> &&ptr, std::shared_ptr<mutex_t> &&mtx_ptr)
: ptr(std::move(ptr))
, mtx_ptr(std::move(mtx_ptr))
{}

public:
template<typename... Args>
safe_ptr(Args... args) : ptr(std::make_shared<T>(args...)), mtx_ptr(std::make_shared<mutex_t>()) {}
static safe_ptr make_safe(Args&&... args) {
return safe_ptr(std::make_shared<T>(std::forward<Args>(args)...), std::make_shared<mutex_t>());
}

auto_lock_t<x_lock_t> operator -> () { return auto_lock_t<x_lock_t>(get_obj_ptr(), *get_mtx_ptr()); }
auto_lock_obj_t<x_lock_t> operator * () { return auto_lock_obj_t<x_lock_t>(get_obj_ptr(), *get_mtx_ptr()); }
Expand Down