23#ifndef HPCOMBI_BUILDER_HPP_
24#define HPCOMBI_BUILDER_HPP_
28#include <initializer_list>
51 using type_elem =
typename std::remove_reference_t<
decltype((TPU{})[0])>;
60 using array = std::array<type_elem, size>;
62 template <
class Fun,
decltype(
size)... Is>
63 static constexpr TPU
make_helper(Fun f, std::index_sequence<Is...>) {
64 static_assert(std::is_invocable_v<Fun, type_elem>);
69 inline constexpr TPU
operator()(std::initializer_list<type_elem> il,
73 std::copy(il.begin(), il.end(),
res.begin());
74 std::fill(
res.begin() + il.size(),
res.end(), def);
75 return reinterpret_cast<const TPU &
>(
res);
79 template <
class Fun>
inline constexpr TPU
operator()(Fun f)
const {
80 static_assert(std::is_invocable_v<Fun, type_elem>);
81 return make_helper(f, std::make_index_sequence<size>{});
102 return reinterpret_cast<const TPU &
>(a);
106 constexpr TPU
id()
const {
110 constexpr TPU
rev()
const {
123 return (*
this)([](
type_elem i) {
return i == 15 ? 15 : i + 1; });
127 return (*
this)([](
type_elem i) {
return i == 0 ? 0 : i - 1; });
132 return (((i & 0x01) != 0 ? 1 : 0) + ((i & 0x02) != 0 ? 1 : 0) +
133 ((i & 0x04) != 0 ? 1 : 0) + ((i & 0x08) != 0 ? 1 : 0) +
134 ((i & 0x10) != 0 ? 1 : 0) + ((i & 0x20) != 0 ? 1 : 0) +
135 ((i & 0x40) != 0 ? 1 : 0) + ((i & 0x80) != 0 ? 1 : 0));
#define HPCOMBI_ASSERT(x)
Definition debug.hpp:31
std::array< std::tuple< uint16_t, uint16_t, std::array< uint16_t, gens.size()> >, 65536 > res
Definition image.cpp:66
VectGeneric< TPUBuild< TPU >::size > & as_VectGeneric(TPU &v)
Cast a HPCombi::epu8 to a c++ HPCombi::VectGeneric.
Definition builder.hpp:162
TPUBuild< TPU >::array & as_array(TPU &v) noexcept
Cast a TPU to a c++ std::array.
Definition builder.hpp:145
Given a transformation from 0..15 → 0..15, build at compile-time the array representing the transform...
Definition builder.hpp:49
constexpr TPU popcount() const
Popcount TPU: the ith entry contains the number of bits set in i.
Definition builder.hpp:130
static constexpr size_t size_elem
Size of the elements.
Definition builder.hpp:54
constexpr TPU left_dup() const
Left shift TPU, duplicating the rightmost entry.
Definition builder.hpp:122
constexpr TPU operator()(int c) const
explicit overloading for int constants
Definition builder.hpp:89
constexpr TPU right_dup() const
Right shift TPU, duplicating the leftmost entry.
Definition builder.hpp:126
constexpr TPU operator()(size_t c) const
explicit overloading for size_t constants
Definition builder.hpp:93
constexpr TPU rev() const
Return the reversed element of type TPU.
Definition builder.hpp:110
constexpr TPU operator()(std::initializer_list< type_elem > il, type_elem def) const
Construct a TPU from an std::initializer_list and a default value.
Definition builder.hpp:69
constexpr TPU operator()(array a) const
explicit overloading for array
Definition builder.hpp:101
constexpr TPU operator()(Fun f) const
Construct a TPU from a function giving the values at .
Definition builder.hpp:79
constexpr TPU right_cycle() const
Right cycle TPU permutation.
Definition builder.hpp:118
constexpr TPU left_cycle() const
Left cycle TPU permutation.
Definition builder.hpp:114
constexpr TPU operator()(type_elem c) const
Construct a constant TPU.
Definition builder.hpp:85
static constexpr TPU make_helper(Fun f, std::index_sequence< Is... >)
Definition builder.hpp:63
constexpr TPU id() const
Return the identity element of type TPU.
Definition builder.hpp:106
typename std::remove_reference_t< decltype((TPU{})[0])> type_elem
Type of the elements.
Definition builder.hpp:51
static constexpr size_t size
Number of elements.
Definition builder.hpp:57
std::array< type_elem, size > array
Array equivalent type.
Definition builder.hpp:60
VectGeneric is to Vect16 what PermGeneric is to Perm16; see PermGeneric.
Definition vect_generic.hpp:56