10 #include <type_traits>
43 static_assert_valid_base_type();
52 template <
typename P>
CRC(P param)
55 static_assert_valid_base_type();
68 return accumulate(str.c_str(), 0, str.length());
108 template <
typename P>
111 static_assert_valid_parameter_type<P>();
112 return accumulate(
reinterpret_cast<char const *
>(&value), 0,
sizeof(P));
146 T
const *
const crcTab(crcTable());
149 const size_t afterLastOffset(offset + length);
151 for (
size_t i = offset; i < afterLastOffset; ++i)
153 mHash = crcTab[(mHash ^ data[i]) & 0xff] ^ (mHash >> 8);
156 mHash = mHash & T(-1);
178 template <
typename Iter>
181 for (Iter it = first; it != last; ++it)
194 T
get()
const {
return mHash; }
200 void static_assert_valid_base_type()
const
202 static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, uint64_t>::value,
"Type should be unsigned 32 or 64.");
207 void static_assert_valid_parameter_type()
const
209 static_assert(std::is_arithmetic<P>::value,
"Type should be arithmetic.");
213 T
const * crcTable()
const
215 return std::is_same<T, uint32_t>::value ?