# Generic Variadic

**URL:** <https://forum.xod.io/t/generic-variadic/783>\
**Category:** Uncategorized\
**Created:** [May 18, 2018, 12:56am UTC](https://forum.xod.io/t/generic-variadic/783 "2018-05-18T00:56:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 18, 2018, 12:56am UTC](https://forum.xod.io/t/generic-variadic/783/1 "2018-05-18T00:56:43Z")

</div>

I just noticed that gweimer/utils/if-else-v isn’t working now that I’ve changed it to use generic pin type. When I try to download utils-example-if-else, it just hangs on Transpiling… Deleting all but the 1st if-else-v block doesn’t seem to make a difference. The other examples still download fine.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [May 18, 2018, 8:36am UTC](https://forum.xod.io/t/generic-variadic/783/2 "2018-05-18T08:36:48Z")

</div>

Doh…, three more “oops”. Long story short, here’s a working `if-else-v` implementation:

![Screenshot%20from%202018-05-18%2010-48-39](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/2ade38641eb53d3f2a1c6ee296a0593ecd167d46.png)

TL;DR

Your original patch was `not-imlemented-in-xod` and we don’t have a system now that projects XOD generics to C++ templates. The system searched for a concrete specialization (`if-else-v(number)` in my experiment) and did not find any, so fail to transpile. That’s expected behavior. The bug is that the problem report does not pop up to a clear message.

When you change `not-imlemented-in-xod` with a trivial XOD implementation using `if-else`, your node is able to work over any type the `if-else` supports. And if you take a look at `xod/core` you’ll find:

- `if-else(number)`
- `if-else(string)`
- …more types to come

Issues created:

- [https://github.com/xodio/xod/issues/1219](https://github.com/xodio/xod/issues/1219)
- [https://github.com/xodio/xod/issues/1220](https://github.com/xodio/xod/issues/1220)
- [https://github.com/xodio/xod/issues/1221](https://github.com/xodio/xod/issues/1221)

Will fix them in 0.20.3 very soon

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 18, 2018, 6:16pm UTC](https://forum.xod.io/t/generic-variadic/783/3 "2018-05-18T18:16:37Z")

</div>

Ah…didn’t think of generics not working with C++. The code just used auto to create vars & code was not type-specific, so I assumed it would work.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 18, 2018, 6:31pm UTC](https://forum.xod.io/t/generic-variadic/783/4 "2018-05-18T18:31:43Z")

</div>

Weird. I am getting this error now that if-else-v uses if-else node:  
Dead reference error  
Patch “xod/core/if-else(number)” is not found in the project

But I can manually add xod/core/if-else(number) to the patch…

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [May 18, 2018, 9:59pm UTC](https://forum.xod.io/t/generic-variadic/783/5 "2018-05-18T21:59:19Z")

</div>

Hmm… That’s strange. Are you sure you indeed have no `xod/core/if-else(number)`? Take a look in the Project Browser. I mean, maybe you have a `xod/core` fork from 0.19.x in your workspace. If the `if-else(number)` specialization presents, we have a new problem 😣 although all worked when I tried to reproduce. Please, confirm or reject.

> [@gweimer](#):
>
> Ah…didn’t think of generics not working with C++

Yes, it should be a separate feature. But, but, but. Today @evgenykochetkov came excited to ask:

— Have you seen how gweimer done his `if-else-v`???!?  
— Yep, it does not work because la-la-la  
— It’s a minor bug related to bla-bla. Think wider. Do you understand C++ generics actually work, right now, without any new features?  
— Huh?  
— Type deduction does la-la, then resolver does foo-bar, then transpiler does baz-qux!…  
— Waait… No way. Indeed!

So, generics actually (and surprisingly) should work when implemented in C++ out of the box. There are few silly bugs that stop it from happening. We planed to release 0.20.3 today but ran out of time and will try again at Monday or Tuesday. That, hopefully, will fix everything.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 18, 2018, 10:51pm UTC](https://forum.xod.io/t/generic-variadic/783/6 "2018-05-18T22:51:15Z")

</div>

> [@nkrkv](#):
>
> Hmm… That’s strange. Are you sure you indeed have no `xod/core/if-else(number)` ?

That was the weird part. I was able to search/add node for if-else(number) in the same patch that would not compile because that node was “missing”. I can try again tomorrow when I’m home, but I had already restarted XOD to re-read my library update. There are only downloaded libraries in `XOD\ __lib__ `. Since it is working for you, hopefully it is a fluke I cannot reproduce…

I’m glad my ignorance helped you see an obvious solution for C++ generics 🙂

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 20, 2018, 6:41pm UTC](https://forum.xod.io/t/generic-variadic/783/7 "2018-05-20T18:41:05Z")

</div>

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/dc0dfeb77a80046c1be988c9ffdf31188eebcbf4.png)

I added the if-else(number) node after getting the error that it doesn’t exist.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [May 21, 2018, 8:54am UTC](https://forum.xod.io/t/generic-variadic/783/8 "2018-05-21T08:54:12Z")

</div>

Black magic. I’ve tried to reproduce exactly the same scenario as I see on the screenshot, but get no error. I’m at 0.20.2. Perhaps, the problem is a consequence of a slight variation of actions we perform. Please, would you share a xodball with the problem project as is? Also, confirm that you’re getting the Dead reference error when perform the steps:

1. Open the xodball
2. Open the `utils-example-if-else` patch
3. “Deploy → Upload to Arduino” with “Debug after upload” checked

Thanks for supporting us in the bug hunting session.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 21, 2018, 1:58pm UTC](https://forum.xod.io/t/generic-variadic/783/9 "2018-05-21T13:58:45Z")

</div>

[gweimer-utils.xodball](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/501fe153d16cd1d2a5c2cfe45d0463dae5600b6c.xodball) (85.3 KB)

Those are the steps I follow to get the error. I’ve been opening my copy of the project up to this point, but I opened the library copy this time & got the same error. I’ve tried deleting & re-adding the if-else node, but it hasn’t made a difference.

I just tried deleting my ` __lib__ /gweimer/utils` link & downloading the library; same result. Also same error if I try to compile in the cloud.

---

<div class="post-metadata">

**Author:** ![evgenykochetkov](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/evgenykochetkov/32/14_2.png) [@evgenykochetkov](https://forum.xod.io/u/evgenykochetkov)\
**Post date:** [May 22, 2018, 6:10pm UTC](https://forum.xod.io/t/generic-variadic/783/10 "2018-05-22T18:10:45Z")

</div>

Thanks for the xodball!  
It is indeed a problem.  
The good news is that we already fixed it while implementing a new feature.  
The bad news is that it’s not yet released and the bug still happens in 0.20.3. But you can use your original generic `if-else-v` implemented in C++

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [May 22, 2018, 7:18pm UTC](https://forum.xod.io/t/generic-variadic/783/11 "2018-05-22T19:18:07Z")

</div>

Success! Thank you.

(now I at least 20 chars for valid reply 🙂 )

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [May 24, 2018, 7:18pm UTC](https://forum.xod.io/t/generic-variadic/783/12 "2018-05-24T19:18:08Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
