Consider a tempalted class InputBuffer
:
template<class Source, size_t Capacity>
class InputBuffer
{
public:
explicit InputBuffer(Source src);
int getchar();
private:
std::byte const* m_read_ptr;
std::byte const* m_last_valid;
Source m_src;
std::array<std::byte, Capacity> m_data;
void fetchAndResetPointers();
};
Question: Should the constructor instead accept src
as a reference and store a pointer instead of taking it by value? It is very likely that the caller expect reference semantics here. However, it is also possible that Source
already is some kind of pointer, and then, taking src
by reference and storing a pointer would lead to an unnecessary indirection. If not passing by reference, the user can use std::ref
if needed.