[swift-evolution] [Design Question] Metaprogramming as a non-goal

Jacob Bandes-Storch jtbandes at gmail.com
Sun Jan 24 03:01:06 CST 2016


I'd guess the point is that the generics system isn't meant to force the
compiler to perform the sorts of things C++'s (Turing-complete) template
system can:

    template<size_t... F>
    struct Fibonacci { };

    // API
    template<size_t n>
    struct Fibonacci<n> {
        static constexpr size_t value = Fibonacci<n, 1, 0>::value;
    };

    // Recursive implementation
    template<size_t n, size_t Fn, size_t Fm>
    struct Fibonacci<n, Fn, Fm> {
        static constexpr size_t value = Fibonacci<n-1, Fn+Fm, Fn>::value;
    };

    // Base case
    template<size_t Fn, size_t Fm>
    struct Fibonacci<0, Fn, Fm> {
        static constexpr size_t value = Fn;
    };

    int main() {
        printf("F(200): %zu\n", Fibonacci<200>::value);
        return 0;
    }

Jacob

On Sat, Jan 23, 2016 at 11:17 PM, Michael Henson via swift-evolution <
swift-evolution at swift.org> wrote:

> In the swift/docs/Generics.rst documentation, I see:
>
> "
> As important as the goals of a feature are the explicit non-goals, which
> we don't want
> or don't need to support:
> * Compile-time "metaprogramming" in any form
> * Expression-template tricks a la Boost.Spirit, POOMA
> "
>
> What kinds of things count as compile-time metaprogramming? I've been
> tinkering with some ideas related to the type system and having a more
> specific description here might help me pare many / most / all of them down.
>
> Mike
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160124/fec6da93/attachment.html>


More information about the swift-evolution mailing list