Skip to content

Commit 3adab51

Browse files
committed
added for loop iterations in sample code
1 parent 66c7308 commit 3adab51

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ target_include_directories(${PROJECT_NAME} INTERFACE ${${PROJECT_NAME}_SOURCE_DI
1515
add_subdirectory(tests)
1616

1717
add_subdirectory(samples)
18+
19+
install(TARGETS circularbuffer DESTINATION lib)

circular_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ typename CircularBuffer<T>::reference CircularBuffer<T>::at(size_t index) {
351351
template<typename T>
352352
inline
353353
typename CircularBuffer<T>::const_reference CircularBuffer<T>::at(size_t index) const {
354+
std::lock_guard<std::mutex> _lck(_mtx);
354355
if((index<0)||(index>=_size))
355356
throw std::out_of_range("Index is out of Range of buffer size");
356357
index += _tail;

samples/sample_circularbuffer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ int main(int argc, char *argv[])
9494
std::cout<<"Checking deference ++ operator "<<*(++it)<<"\n";
9595
std::cout<<"Checking deference -- operator "<<*(--it)<<"\n";
9696

97+
98+
std::cout<<"Checking iterator for loop \n";
99+
for(auto it:test_stringbuf)
100+
std::cout<<"Checking for loop function "<<it<<"\n";
101+
102+
std::cout<<"Checking for loop with iterator \n";
103+
for(auto it = test_stringbuf.begin(); it != test_stringbuf.end(); it++)
104+
std::cout<<"Checking for loop function "<<*it<<"\n";
105+
97106
CircularBuffer<test_struct> test_structbuf{5};
98107
std::cout<<"Checking [] operator"<<test_structbuf[0]<<"\n";
99108

@@ -127,8 +136,8 @@ int main(int argc, char *argv[])
127136
std::cout<<"Checking [] in copybuffer"<<test_stringbufcopy[1]<<"\n";
128137
std::cout<<"Checking maxsize buffer"<<test_stringbuf.capacity()<<"\n";
129138
std::cout<<"Checking size buffer"<<test_stringbuf.size()<<"\n";
130-
131139
return 0;
132140
}
133141

134142

143+

0 commit comments

Comments
 (0)