libdpf/test/tests/helpers/domain_walk.hpp

25 lines
903 B
C++
Raw Normal View History

#ifndef LIBDPF_TEST_TESTS_HELPERS_DOMAIN_WALK_HPP__
#define LIBDPF_TEST_TESTS_HELPERS_DOMAIN_WALK_HPP__
// eval_interval / eval_full emit points in integer order of the input bits
// (the same order as operator++ for ordinary integers). xor_wrapper::operator++
// is characteristic-2 addition, XOR 1, so it does not walk that domain.
template <typename InputT>
InputT next_domain_point(InputT cur)
{
if constexpr (dpf::utils::has_characteristic_two_v<InputT>)
{
using narrow = dpf::utils::integral_type_from_bitlength_t<dpf::utils::bitlength_of_v<InputT>>;
auto bits = static_cast<narrow>(dpf::utils::to_integral_type<InputT>{}(cur));
bits = static_cast<narrow>(bits + narrow{1});
return dpf::utils::make_from_integral_value<InputT>{}(bits);
}
else
{
++cur;
return cur;
}
}
#endif // LIBDPF_TEST_TESTS_HELPERS_DOMAIN_WALK_HPP__