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
Peek API to view data of buffer without popping #6309
Conversation
I believe this falls under "feature" Does the Circular Buffer have tests? Could we add a test covering this function? |
* @param data Data to be peeked from the buffer | ||
* @return True if the buffer is not empty and data contains a transaction, false otherwise | ||
*/ | ||
bool peek(T& data) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, does data need to be const if peek is a const member function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const member function is not allowed to modify the object elements, which is not done in case of this API. But we are passing data as return value hence it cannot be const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be an issue if it was a const reference (T& const data
). But since it's a reference-to-const (const T& data
), it should be fine.
Does this compile as is with a const CircularBuffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all members of CircularBuffer are const, without this API also it won't compile as const CircularBuffer.
(const T& data)
in case of template class says value of data variable cannot be modified in the function. We are passing the data value, hence it cannot be const. I tried compilation with const and it failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's annoying if there's a similar issue in other functions.
const T& data
can be assigned with issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/morph build |
Build : SUCCESSBuild number : 1503 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 1146 |
Test : SUCCESSBuild number : 1286 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 1157 |
Description
Added
peek
API to view data of CircularBuffer without popping.Pull request type