Skip to content

Commit

Permalink
feat: restrict methods to l-values
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 25, 2023
1 parent fb3b682 commit 7298ee6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(lockpp LANGUAGES CXX VERSION 2.4)
project(lockpp LANGUAGES CXX VERSION 2.5)

# --------------------------------------------------------------------------------------------------------
# Library options
Expand Down
4 changes: 2 additions & 2 deletions include/lockpp/lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace lockpp

public:
template <template <typename> class Lock = write_lock, typename... LockArgs>
[[nodiscard]] locked<Type, Lock<Mutex>> write(LockArgs &&...);
[[nodiscard]] locked<Type, Lock<Mutex>> write(LockArgs &&...) &;

public:
template <template <typename> class Lock = read_lock, typename... LockArgs>
[[nodiscard]] locked<const Type, Lock<Mutex>> read(LockArgs &&...) const;
[[nodiscard]] locked<const Type, Lock<Mutex>> read(LockArgs &&...) const &;

public:
template <typename O>
Expand Down
4 changes: 2 additions & 2 deletions include/lockpp/lock.inl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace lockpp

template <typename Type, decayed Mutex>
template <template <typename> class Lock, typename... LockArgs>
locked<Type, Lock<Mutex>> lock<Type, Mutex>::write(LockArgs &&...lock_args)
locked<Type, Lock<Mutex>> lock<Type, Mutex>::write(LockArgs &&...lock_args) &
{
return {&m_value, m_mutex, std::forward<LockArgs>(lock_args)...};
}

template <typename Type, decayed Mutex>
template <template <typename> class Lock, typename... LockArgs>
locked<const Type, Lock<Mutex>> lock<Type, Mutex>::read(LockArgs &&...lock_args) const
locked<const Type, Lock<Mutex>> lock<Type, Mutex>::read(LockArgs &&...lock_args) const &
{
return {&m_value, m_mutex, std::forward<LockArgs>(lock_args)...};
}
Expand Down
4 changes: 2 additions & 2 deletions include/lockpp/locked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace lockpp
locked(Type *, lock_mutex_t<Lock> &, LockArgs &&...);

public:
[[nodiscard]] Type &operator*() const noexcept;
[[nodiscard]] Type *operator->() const noexcept;
[[nodiscard]] Type &operator*() const & noexcept;
[[nodiscard]] Type *operator->() const & noexcept;
};
} // namespace lockpp

Expand Down
4 changes: 2 additions & 2 deletions include/lockpp/locked.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace lockpp
}

template <typename Type, class Lock>
[[nodiscard]] Type &locked<Type, Lock>::operator*() const noexcept
[[nodiscard]] Type &locked<Type, Lock>::operator*() const & noexcept
{
return *m_value;
}

template <typename Type, class Lock>
[[nodiscard]] Type *locked<Type, Lock>::operator->() const noexcept
[[nodiscard]] Type *locked<Type, Lock>::operator->() const & noexcept
{
return m_value;
}
Expand Down

0 comments on commit 7298ee6

Please sign in to comment.