Closed ghost closed 6 years ago
Hi, Thanks for your report. I looks like the documentation for Variant field got a bit outdated. Sorry about that, I'll fix it in the next release (which I plan to do until the end of the year).
At some stage I decided to add also a compile time information about the index of the handled field within the held tuple. Just add template
struct MyVariantHandler
{
template <std::size_t TIdx>
void operator()(Property1& prop)
{
static_assert(TIdx == 0, "Wrong index");
}
template <std::size_t TIdx>
void operator()(Property2& prop) {...}
template <std::size_t TIdx>
void operator()(Property3& prop) {...}
};
You can also look at test70 in my unit-tests for fields for the example.
By the way, may I ask you why you decided to use Variant field in your protocol? It's not very efficient. The complexity of the "read" operation is O(n), while the complexity of "dispatch to handling" operation is O(log(n)). I had to introduce it in order to support unordered key/value pairs of various properties in MQTTv5 protocol (my work is here), but I would not choose such data layout in the protocols I'm defining. Are you going to define a new internal protocol that you are in complete control of what's going inside, or you have to implement already defined protocol, that requires you to use the Variant field to support it? If you don't want to post your answer in the public ticket, please send me a direct e-mail to arobenko@gmail.com.
Regards, Alex
Thank you Alex, works fine.
Hi,
Thank you for you great job, the library design is very smart and we are projecting to use it in commercial projects...
Just one issue we cannot solve with Variant and VariantHandler (following documentation exemples):
This code doesn't compile with the following error :
error: no member named 'operator()' in 'MyVariantHandler' func_.template operator()<TIdx>(*(reinterpret_cast<TField*>(storage_)))
I'm using Xcode with LLVM 9.0, clang-900.0.39.2. I have also try with gcc 5.4.1 with the same error. It seems the template resolution doesn't match, but how to implement MyVariantHandler to make this work?
Regards,