template<typename T>
struct tts::enumeration< T >
Enumerates the values of a type in increasing order.
Gives each value of T its rank, its position among the values of T in increasing order. tts::sweep and tts::sample take the values of an argument from the ranks of its type.
Specialized for every integer type of at most 8 bytes, and for every floating-point type of 4 or 8 bytes. A specialization for another type, with last, index, and value, makes that type usable with tts::sweep and tts::sample.
#define TTS_MAIN
#include <tts/tts.hpp>
#include <array>
#include <cstdint>
TTS_CASE(
"Ranks of the values of an integer")
{
TTS_EQUAL(ranks::value(255), std::int8_t {127});
};
TTS_CASE(
"Ranks of the values of a float")
{
TTS_EQUAL(ranks::index(0.f), ranks::index(-0.f) + 1);
TTS_LESS(ranks::index(-1.f), ranks::index(1.f));
TTS_EQUAL(ranks::value(ranks::index(1.5f)), 1.5f);
};
enum class rounding
{
down,
nearest,
up
};
double shift(rounding r)
{
return static_cast<double>(r) - 1.;
}
namespace tts
{
template<>
struct display<rounding>
{
static text render(rounding r)
{
std::array names {"down", "nearest", "up"};
return text {names[ static_cast<std::size_t>(r) ]};
}
};
{
static constexpr std::uint64_t
last = 2;
static constexpr std::uint64_t
index(rounding r)
noexcept
{
return static_cast<std::uint64_t>(r);
}
static constexpr rounding
value(std::uint64_t i)
noexcept
{
return static_cast<rounding>(i);
}
};
}
TTS_CASE(
"Sweep over the values of a user-defined type")
{
};
- Template Parameters
-
| T | Type whose values are enumerated |