Limitation of std::variant
Posted: April 14th, 2019, 5:59 pm
Yeah, I'm still messing with std::variant for some reason, but I did find a possible limitation albeit probably implementation defined.
While messing around I wanted to add some templates to a variant list, but in order for this to work afaik, you can only add instantiated objects to the variant list. In other words, you couldn't just add std::vector to the list, you'd have to add std::vector<int>. So the templates that I wanted to add had a non-type parameter, an integer instead of a type like int or float. This should be fine because my templates have a set number of possible instantiations, 256 to be exact. While that is a lot to add to the list: std::variant< temp<0>, temp<1>, ..., temp<255> >; I was able to use some copy/paste and multi-line edits to make short work of it.
Well, no issues in the declaration, my variant now had over 300 items in the list. The problem came when I tried to use std::visit. It kept saying there was no overload for the visitor and variant combination I was using. I thought this was strange, so I made a smaller test of 80 items, didn't work. I decided to take away items until it did work, and it started working once I only had 64 items in the variant list.
I'm wondering it this is a VS limitation or a standards limitation. Also, would the limitation be due to recursive depth limitations, which I think the standards only gives a minimum recursive depth limitation. Of course now that I say that, I can't find the table I've come across in the past.
While messing around I wanted to add some templates to a variant list, but in order for this to work afaik, you can only add instantiated objects to the variant list. In other words, you couldn't just add std::vector to the list, you'd have to add std::vector<int>. So the templates that I wanted to add had a non-type parameter, an integer instead of a type like int or float. This should be fine because my templates have a set number of possible instantiations, 256 to be exact. While that is a lot to add to the list: std::variant< temp<0>, temp<1>, ..., temp<255> >; I was able to use some copy/paste and multi-line edits to make short work of it.
Well, no issues in the declaration, my variant now had over 300 items in the list. The problem came when I tried to use std::visit. It kept saying there was no overload for the visitor and variant combination I was using. I thought this was strange, so I made a smaller test of 80 items, didn't work. I decided to take away items until it did work, and it started working once I only had 64 items in the variant list.
I'm wondering it this is a VS limitation or a standards limitation. Also, would the limitation be due to recursive depth limitations, which I think the standards only gives a minimum recursive depth limitation. Of course now that I say that, I can't find the table I've come across in the past.