TTS v4.1.0
The Tiny Test System
Loading...
Searching...
No Matches
tts::adapter< T > Struct Template Reference

Make a type usable in a range check. More...

Detailed Description

template<typename T>
struct tts::adapter< T >

Make a type usable in a range check.

A range check stores its data as scalars, and a specialization maps a type to them: element_type is the scalar, size the number of scalars per value, load and store the conversions between a value and size consecutive scalars. The primary template covers a scalar type, with size equal to one. A specialization also keeps whole a result that follows the protocol of structured bindings, which the primary template splits into its members.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <array>
// A type of four scalars
using pack4 = std::array<float, 4>;
pack4 twice(pack4 const& x)
{
return {2 * x[ 0 ], 2 * x[ 1 ], 2 * x[ 2 ], 2 * x[ 3 ]};
}
namespace tts
{
// One pack4 per four consecutive scalars
template<> struct adapter<pack4>
{
using element_type = float;
static constexpr std::size_t size = 4;
static pack4 load(float const* src)
{
return {src[ 0 ], src[ 1 ], src[ 2 ], src[ 3 ]};
}
static void store(pack4 const& v, float* dst)
{
for(std::size_t i = 0; i < 4; ++i)
dst[ i ] = v[ i ];
}
};
}
TTS_CASE("Range check of a function on packs against its scalar reference")
{
auto twice_scalar = [](float x) { return 2 * x; };
TTS_ULP_RANGE_CHECK(tts::between(-100.f, 100.f), float, pack4, twice_scalar, twice, 0.);
};
Template Parameters
TType to adapt