martinmoene / variant-lite

variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
239 stars 25 forks source link

Support for multiple identical types? #40

Closed AnthonyVH closed 3 years ago

AnthonyVH commented 3 years ago

The current implementation of variant-lite does not support multiple identical types (i.e. nonstd::variant<int, int>). On the other hand, this works perfectly fine in C++17's std::variant.

Are there any plans to support this as well in variant-lite? If so, what exactly prevents it from working right now? I can't think of a technical issue implementing this in C++11, but I have no clue about C++98.

martinmoene commented 3 years ago

@AnthonyVH Thanks for your interest in variant-lite.

I didn't have plans to support multiple identical types. I cannot answer the question what is preventing it now, although it may well have to do with what C++98 is capable of or not.

It isn't likely I can, or choose to spend time on this any time soon I'm afraid.

AnthonyVH commented 3 years ago

No worries. I messed around with the code a bit tonight and I think I it working like exactly like std::variant.

I'll try to get the required macro and template mess cleaned up and create a pull request.

martinmoene commented 3 years ago

Just to be sure: include/variant.hpp is generated from template/variant.hpp using script/generate_header.py.

Something I sometimes forgot myself ;)

AnthonyVH commented 3 years ago

Thanks for merging this in! I just noticed that I forgot to update the readme though, that still says all types must be different. Do you want to change this, or shall I create a new pull request?

martinmoene commented 3 years ago

You're welcome :)

Having a look at the old requirement of different type did cross my mind, but didn't follow through. I'll take care of it.