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

const correctness and explicit constructor #18

Merged
merged 2 commits into from
Mar 13, 2018
Merged
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
10 changes: 5 additions & 5 deletions examples/cpp/circular_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
template <class T>
class circular_buffer {
public:
circular_buffer(size_t size) :
explicit circular_buffer(size_t size) :
buf_(std::unique_ptr<T[]>(new T[size])),
size_(size)
{
Expand All @@ -32,7 +32,7 @@ class circular_buffer {
}
}

T get(void)
T get(void) const
{
std::lock_guard<std::mutex> lock(mutex_);

Expand All @@ -54,19 +54,19 @@ class circular_buffer {
head_ = tail_;
}

bool empty(void)
bool empty(void) const
{
//if head and tail are equal, we are empty
return head_ == tail_;
}

bool full(void)
bool full(void) const
{
//If tail is ahead the head by 1, we are full
return ((head_ + 1) % size_) == tail_;
}

size_t size(void)
size_t size(void) const
{
return size_ - 1;
}
Expand Down