math icon indicating copy to clipboard operation
math copied to clipboard

Remove `stan::math::forward_as`, prefer `if constexpr`

Open WardBrian opened this issue 7 months ago • 0 comments

Now that we're requiring C++17, cleaning up these forward_as workarounds throughout the codebase would be nice.

This is also described in the Stan Math Developer docs:

If we used C++17, the above would become

T_partials_return cdf(1.0);
if constexpr (is_vector<T_y>::value || is_vector<T_inv_scale>::value) {
 cdf = one_m_exp.prod();
} else {
 cdf = one_m_exp;
}

Where if constexpr is run before any tests are done to verify the code can be compiled.

Originally posted by @andrjohns in #3189

WardBrian avatar Jun 04 '25 16:06 WardBrian