1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-09 17:29:36 +00:00

Better templates the CRC generator.

This commit is contained in:
Thomas Harte 2020-01-27 00:03:01 -05:00
parent 5975fc8e63
commit 561e149058

View File

@ -66,9 +66,23 @@ template <typename T, T reset_value, T xor_output, bool reflect_input, bool refl
[add all data from @c data]
get_value()
*/
T compute_crc(const std::vector<uint8_t> &data) {
template <typename Collection> T compute_crc(const Collection &data) {
return compute_crc(data.begin(), data.end());
}
/*!
A compound for:
reset()
[add all data from @c begin to @c end]
get_value()
*/
template <typename Iterator> T compute_crc(Iterator begin, Iterator end) {
reset();
for(const auto &byte: data) add(byte);
while(begin != end) {
add(*begin);
++begin;
}
return get_value();
}