msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
3.03k stars 883 forks source link

Fix compilation error when `std::variant` has the same types #1112

Closed uyha closed 7 months ago

uyha commented 7 months ago

@redboltz could you have a look and create a minor release if everything is good? I need this for my project.

codecov-commenter commented 7 months ago

Codecov Report

Merging #1112 (d812fa5) into cpp_master (e9e06a5) will not change coverage. The diff coverage is 50.00%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## cpp_master #1112 +/- ## =========================================== Coverage 85.75% 85.75% =========================================== Files 80 80 Lines 5091 5091 =========================================== Hits 4366 4366 Misses 725 725 ```
redboltz commented 7 months ago

Thank you for sending the PR. I didn't know about in_place_index_t. It can clarify the index! I will merge it and will release the updated version ASAP.

Just my curious, when do you use std::variant that contains the same types?

uyha commented 7 months ago

I have a very heavy template code base and there's basically a type list that is a list of events. For example,

using Events = TypeList<Event1, Event2, Event3>;

This list will be used as common source for events coming in and out. Sometimes, the event list isn't used as is because the receiving end doesn't accept an "event", but some modified version of those "event"s and a modified version can be

template<typename>
using TimePoint = std::chrono::system_clock::time_point_t;

So a receiving end can sometimes accept a std::variant<Event1, Event2, Event3> and sometimes it can accept a std::variant<TimePoint<Event1>, TimePoint<Event2>, TimePoint<Event3>> (which is a variant having same types).

(I'm not sure if I make it clearer or not, if you want to know more, please let me know)

redboltz commented 7 months ago

Thank you for the comment. I understand your situation. Good to know :)