https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88694

--- Comment #2 from Amos Bird <amosbird at gmail dot com> ---
Currently by introducing a `auto local_i = decltype(i)();` can workaround this.



#include <iostream>
#include <tuple>
#include <utility>

template <typename T, T Begin, class Func, T... Is>
constexpr void static_for_impl(Func&& f, std::integer_sequence<T, Is...>) {
    (f(std::integral_constant<T, Begin + Is>{}), ...);
}

template <typename T, T Begin, T End, class Func> constexpr void
static_for(Func&& f) {
    static_for_impl<T, Begin>(std::forward<Func>(f),
std::make_integer_sequence<T, End - Begin>{});
}

struct Foo {
    template <int x> void print() { std::cout << x << std::endl; }
};

int main() {
    Foo foo;
    static_for<int, 0, 3>([&](auto i) {
        [&]() {
            auto local_i = decltype(i)();
            foo.print<local_i>();
        }();
    });
    return 0;
}

Reply via email to