since.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. ##[
  2. `since` is used to emulate older versions of nim stdlib with `--useVersion`,
  3. see `tuse_version.nim`.
  4. If a symbol `foo` is added in version `(1,3,5)`, use `{.since: (1.3.5).}`, not
  5. `{.since: (1.4).}`, so that it works in devel in between releases.
  6. The emulation cannot be 100% faithful and to avoid adding too much complexity,
  7. `since` is not needed in those cases:
  8. * if a new module is added
  9. * if an overload is added
  10. * if an extra parameter to an existing routine is added
  11. ]##
  12. template since*(version: (int, int), body: untyped) {.dirty.} =
  13. ## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
  14. ## or equal to `version`. Usage:
  15. ##
  16. ## .. code-block:: Nim
  17. ## proc fun*() {.since: (1, 3).}
  18. ## since (1, 3): fun()
  19. when (NimMajor, NimMinor) >= version:
  20. body
  21. template since*(version: (int, int, int), body: untyped) {.dirty.} =
  22. ## Evaluates `body` if ``(NimMajor, NimMinor, NimPatch)`` is greater than
  23. ## or equal to `version`. Usage:
  24. ##
  25. ## .. code-block:: Nim
  26. ## proc fun*() {.since: (1, 3, 1).}
  27. ## since (1, 3, 1): fun()
  28. when (NimMajor, NimMinor, NimPatch) >= version:
  29. body