Skip to content

Commit

Permalink
Allow more elements for structured bindings, see #73
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Apr 17, 2024
1 parent cb9551a commit 83287f3
Showing 1 changed file with 45 additions and 105 deletions.
150 changes: 45 additions & 105 deletions include/tao/pq/internal/aggregate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ namespace tao::pq::internal
template< typename T, std::size_t N >
inline constexpr std::size_t count_aggregate_args< T, N, false > = N - 1;

#define TAO_PQ_TIE( N, ... ) \
if constexpr( cnt == N ) { \
const auto& [ __VA_ARGS__ ] = value; \
return std::tie( __VA_ARGS__ ); \
} \
else \
static_assert( true )

#define TAO_PQ_10( P ) P##0, P##1, P##2, P##3, P##4, P##5, P##6, P##7, P##8, P##9
#define TAO_PQ_TIE10( N, ... ) \
TAO_PQ_TIE( N, __VA_ARGS__ ); \
TAO_PQ_TIE( N + 1, __VA_ARGS__, a ); \
TAO_PQ_TIE( N + 2, __VA_ARGS__, a, b ); \
TAO_PQ_TIE( N + 3, __VA_ARGS__, a, b, c ); \
TAO_PQ_TIE( N + 4, __VA_ARGS__, a, b, c, d ); \
TAO_PQ_TIE( N + 5, __VA_ARGS__, a, b, c, d, e ); \
TAO_PQ_TIE( N + 6, __VA_ARGS__, a, b, c, d, e, f ); \
TAO_PQ_TIE( N + 7, __VA_ARGS__, a, b, c, d, e, f, g ); \
TAO_PQ_TIE( N + 8, __VA_ARGS__, a, b, c, d, e, f, g, h ); \
TAO_PQ_TIE( N + 9, __VA_ARGS__, a, b, c, d, e, f, g, h, i );

template< typename T >
constexpr auto tie_aggregate( const T& value ) noexcept
{
Expand All @@ -52,114 +73,33 @@ namespace tao::pq::internal
}
else {
constexpr auto cnt = count_aggregate_args< T >;
if constexpr( cnt == 1 ) {
const auto& [ a ] = value;
return std::tie( a );
}
else if constexpr( cnt == 2 ) {
const auto& [ a, b ] = value;
return std::tie( a, b );
}
else if constexpr( cnt == 3 ) {
const auto& [ a, b, c ] = value;
return std::tie( a, b, c );
}
else if constexpr( cnt == 4 ) {
const auto& [ a, b, c, d ] = value;
return std::tie( a, b, c, d );
}
else if constexpr( cnt == 5 ) {
const auto& [ a, b, c, d, e ] = value;
return std::tie( a, b, c, d, e );
}
else if constexpr( cnt == 6 ) {
const auto& [ a, b, c, d, e, f ] = value;
return std::tie( a, b, c, d, e, f );
}
else if constexpr( cnt == 7 ) {
const auto& [ a, b, c, d, e, f, g ] = value;
return std::tie( a, b, c, d, e, f, g );
}
else if constexpr( cnt == 8 ) {
const auto& [ a, b, c, d, e, f, g, h ] = value;
return std::tie( a, b, c, d, e, f, g, h );
}
else if constexpr( cnt == 9 ) {
const auto& [ a, b, c, d, e, f, g, h, i ] = value;
return std::tie( a, b, c, d, e, f, g, h, i );
}
else if constexpr( cnt == 10 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j );
}
else if constexpr( cnt == 11 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k );
}
else if constexpr( cnt == 12 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l );
}
else if constexpr( cnt == 13 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m );
}
else if constexpr( cnt == 14 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n );
}
else if constexpr( cnt == 15 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o );
}
else if constexpr( cnt == 16 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p );
}
else if constexpr( cnt == 17 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q );
}
else if constexpr( cnt == 18 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r );
}
else if constexpr( cnt == 19 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s );
}
else if constexpr( cnt == 20 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t );
}
else if constexpr( cnt == 21 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u );
}
else if constexpr( cnt == 22 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v );
}
else if constexpr( cnt == 23 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w );
}
else if constexpr( cnt == 24 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x );
}
else if constexpr( cnt == 25 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y );
}
else if constexpr( cnt == 26 ) {
const auto& [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z ] = value;
return std::tie( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z );
}
// TODO: more...

TAO_PQ_TIE( 1, a );
TAO_PQ_TIE( 2, a, b );
TAO_PQ_TIE( 3, a, b, c );
TAO_PQ_TIE( 4, a, b, c, d );
TAO_PQ_TIE( 5, a, b, c, d, e );
TAO_PQ_TIE( 6, a, b, c, d, e, f );
TAO_PQ_TIE( 7, a, b, c, d, e, f, g );
TAO_PQ_TIE( 8, a, b, c, d, e, f, g, h );
TAO_PQ_TIE( 9, a, b, c, d, e, f, g, h, i );

TAO_PQ_TIE10( 10, TAO_PQ_10( a ) );
TAO_PQ_TIE10( 20, TAO_PQ_10( a ), TAO_PQ_10( b ) );
TAO_PQ_TIE10( 30, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ) );
TAO_PQ_TIE10( 40, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ) );
TAO_PQ_TIE10( 50, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ), TAO_PQ_10( e ) );
TAO_PQ_TIE10( 60, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ), TAO_PQ_10( e ), TAO_PQ_10( f ) );
TAO_PQ_TIE10( 70, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ), TAO_PQ_10( e ), TAO_PQ_10( f ), TAO_PQ_10( g ) );
TAO_PQ_TIE10( 80, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ), TAO_PQ_10( e ), TAO_PQ_10( f ), TAO_PQ_10( g ), TAO_PQ_10( h ) );
TAO_PQ_TIE10( 90, TAO_PQ_10( a ), TAO_PQ_10( b ), TAO_PQ_10( c ), TAO_PQ_10( d ), TAO_PQ_10( e ), TAO_PQ_10( f ), TAO_PQ_10( g ), TAO_PQ_10( h ), TAO_PQ_10( i ) );
}
}

#undef TAO_PQ_TIE
#undef TAO_PQ_10
#undef TAO_PQ_TIE10

} // namespace tao::pq::internal

#endif

0 comments on commit 83287f3

Please sign in to comment.