Код
template<typename T, uint16_t Size, typename S = uint8_t>
class ring_buffer
class ring_buffer
тип S uint8_t? На мой взгляд заложена потенциальная опасность при использовании умолчания шаблона.
Код:
CODE
#include <iostream>
#include "usrlib.h"
using namespace std;
#define RFBUF_SIZE 1024
#define DTBUF_SIZE 255
usr::ring_buffer<uint8_t, RFBUF_SIZE, uint16_t> full_description;
usr::ring_buffer<uint8_t, RFBUF_SIZE> short_description;
uint8_t databuf[DTBUF_SIZE];
int main()
{
for(uint8_t i=0; i < DTBUF_SIZE; i++)
databuf[i] = i;
full_description.write(&databuf[0], DTBUF_SIZE - 8);
short_description.write(&databuf[0], DTBUF_SIZE - 8);
cout << dec;
cout << "full_description: get_count = " << full_description.get_count() << " get_free_size = " << full_description.get_free_size() << endl;
cout << "short_description: get_count = " << short_description.get_count() << " get_free_size = " << short_description.get_free_size() << endl;
full_description.write(&databuf[0], DTBUF_SIZE - 8);
short_description.write(&databuf[0], DTBUF_SIZE - 8);
cout << "full_description: get_count = " << full_description.get_count() << " get_free_size = " << full_description.get_free_size() << endl;
cout << "short_description: get_count = " << short_description.get_count() << " get_free_size = " << short_description.get_free_size() << endl;
return 0;
}
Вывод:
Код
full_description: get_count = 247 get_free_size = 777
short_description: get_count = ч get_free_size =
full_description: get_count = 494 get_free_size = 530
short_description: get_count = о get_free_size =
short_description: get_count = ч get_free_size =
full_description: get_count = 494 get_free_size = 530
short_description: get_count = о get_free_size =
При включенных предупреждениях компилятора потенциальная опасность видна сразу.
Вопрос: из каких соображений в шаблоне по умолчанию тип S не совпадает с типом Size?
Спасибо.