On Fri, 11 Jul 2025 at 18:12, Jonathan Wakely <jwak...@redhat.com> wrote:
> > >  +    static constexpr std::array<result_type, __n / 2> multipliers =
> > >  +       philox_engine::__popMultArray();
> > >  +    static constexpr std::array<result_type, __n / 2> round_consts =
> > >  +       philox_engine::__popConstArray();
>
> Since you're creating static data members for these anyway, would it
> make more sense for them to just be variable templates instead of
> calling

Sorry, ignore this incomplete sentence, I changed my mind about
variable templates and wrote this instead ...

> Can we just use a single function for both of these?
>
> template<size_t _Ind0, size_t _Ind1>
> static constexpr array<result_type, __n/2>
> _S_populate_array()
> {
>   if constexpr (__n == 4)
>     return {__consts...[_Ind0], __consts[_Ind1]};
>   else
>     return {__consts...[_Ind0]};
> }
>
> then:
>
>     static constexpr std::array<result_type, __n / 2> multipliers
>        = _S_populate_array<0, 2>();
>     static constexpr std::array<result_type, __n / 2> round_consts
>        = _S_populate_array<1, 3>();
>

Or slightly simpler:

template<int _Offset>
static constexpr array<result_type, __n/2>
_S_populate_array()
{
  if constexpr (__n == 4)
    return {__consts...[_Offset], __consts...[_Offset+2]};
  else
    return {__consts...[_Offset]};
}

    static constexpr std::array<result_type, __n / 2> multipliers
       = _S_populate_array<0>();
    static constexpr std::array<result_type, __n / 2> round_consts
       = _S_populate_array<1>();

Reply via email to