[Dlang Episode 85] D Language - Function Templates - Part 2 of n - Generic Programming

Поділитися
Вставка
  • Опубліковано 8 чер 2024
  • ►Full DLang Series Playlist: • D Language (DLang) Pro...
    ►Find full courses on: courses.mshah.io/
    ►Join as member to get perks: / @mikeshah
    ►Lesson Description: In this lesson I will introduce function templates. Function templates allow us to reuse functions with different types. The D language uses ()'s before our paramter list and the the '!' for instantiating each function template. D is smart enough to 'deduce' using implicit function template instantiation (IFTI) in many cases the data types to further save us from writing out all the details (in fact, this is what writeln very frequently does for us!)
    ►Please like and subscribe to help the channel!
    ►UA-cam Channel: / mikeshah
    ►Join our free community: courses.mshah.io/communities/...
  • Наука та технологія

КОМЕНТАРІ • 9

  • @CosmicCoder
    @CosmicCoder Місяць тому +1

    Very glad to see you back on Dlang again Mike!

    • @MikeShah
      @MikeShah  Місяць тому

      Cheers! Still got another 50+ episodes planned, they'll keep rolling out 🙂

  • @disdroid
    @disdroid Місяць тому +1

    I like mixin templates because they carry their own scope but they access the outer scope too, during instaniation. So its an alternative to virtual methods with the dispatch done using the compiler. Ive moved from using static if all over the place to using small functions with the ctfe logic done using the contracts.

    • @bsdooby
      @bsdooby Місяць тому +1

      can you provide a short example?

    • @disdroid
      @disdroid Місяць тому +2

      ​@@bsdooby not in the comments but there's an experimental project of mine called yyd in the repository. my coregrammars has some too where pegged grammars are used to transform input into a tuple format, using mixin templates to allow for extensibility via the outer scope.
      one difference to ordinary templates is that a mixin template can't be eponymous - so you cant just name a function the same as the template name, you need an additional symbol and an extra step to extract the result. you can't do the mixin inline either - it has to be a separate statement.

    • @MikeShah
      @MikeShah  Місяць тому +1

      @@disdroid Very cool stuff -- thanks for sharing! mixin templates are going to be one of the next videos -- they are just such a powerful feature of the D language, and comparatively simple to use versus other languages.

    • @disdroid
      @disdroid Місяць тому

      @@MikeShah those two projects are my first attempt at using them extensively - the idea i'm having is to make compile-time compilers so that we can include source code from other languages. I'm imagining the output from the compiler would be a mixin template that renders into a tuple enum. to add symbols to the languages, simply import or define them in the outer scope.

  • @Chupe_chupe
    @Chupe_chupe Місяць тому +1

    Gratis video