# Parametric \`var\`

**URL:** <https://forum.modular.com/t/parametric-var/1378>\
**Category:** Language Design\
**Created:** [May 6, 2025, 2:29pm UTC](https://forum.modular.com/t/parametric-var/1378 "2025-05-06T14:29:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![samufi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@samufi](https://forum.modular.com/u/samufi)\
**Post date:** [May 8, 2025, 3:31pm UTC](https://forum.modular.com/t/parametric-var/1378/3 "2025-05-08T15:31:48Z")

</div>

For larecs, I have implemented a [comptime version of optional](https://github.com/samufi/larecs/blob/main/src/larecs/comptime_optional.mojo), which has a zero memory footprint if it is empty. Maybe I should make a proposal to add it to the stlib =).

This makes the following possible:

```python
from larecs.comptime_optional import ComptimeOptional
from sys.info import sizeof

struct S[has_value: Bool = False]:
   var _value: ComptimeOptional[Int, has_value]

   fn __init__ (out self, value: ComptimeOptional[Int, has_value] = None):
      self._value = value

def main():
   s0 = S()
   s1 = S(1)

   print("Size of s0 =", sizeof[__type_of(s0)]())
   print("Size of s1 =", sizeof[__type_of(s1)]())

   @parameter
   if s0.has_value:
      print(s0._value.value())

   @parameter
   if s1.has_value:
      print(s1._value.value())

```

Output:

```auto
Size of s0 = 0
Size of s1 = 8
1

```

---

_[View the full topic](https://forum.modular.com/t/parametric-var/1378)._
