Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70258

Re: issues with std::variant

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: issues with std::variant
Date 2019-12-04 22:39 +0100
Organization A noiseless patient Spider
Message-ID <qs991n$80l$1@dont-email.me> (permalink)
References <d24af259-867c-49b3-a747-e3d4e932ae4a@googlegroups.com> <dbd3f501-3e95-44a9-bdd5-8709f404cda8@googlegroups.com> <8db3e20f-1434-4cd8-b979-b0d1ecb6e643@googlegroups.com> <8ce5173d-19e9-4bd3-8db1-cd22ff443ecc@googlegroups.com> <f0062225-f506-4306-9d48-1e15215f72d1@googlegroups.com>

Show all headers | View raw


On 04.12.2019 22:09, Taylor wrote:
> On Wednesday, December 4, 2019 at 12:31:31 PM UTC-8, Öö Tiib wrote:
>> On Wednesday, 4 December 2019 21:07:37 UTC+2, Taylor  wrote:
>>> Thanks for your help!
>>>
>>> On Wednesday, December 4, 2019 at 10:26:52 AM UTC-8, Öö Tiib wrote:
>>>> On Wednesday, 4 December 2019 18:37:50 UTC+2, Taylor  wrote:
>>>>> I'm using std::variant in my code for one very important type (`Node`). This variant has 68 different types in it. There are two issues:
>>>>>
>>>>> 1. Compile times are extremely slow (~30s per file), due to variant visitation. I'm an indie developer and I don't want to have to buy a new computer (might only be a factor of two faster anyway).
>>>>>
>>>>> 2. If I hire a contractor to help, they might be baffled by the c++ fancyness, such as:
>>>>>
>>>>> Node setExposedPosition(Node node, Vec2 p) {
>>>>>      std::visit(overloaded {
>>>>>        [p](auto& n, decltype(n.exposedPosition)* = nullptr) {
>>>>>          n.exposedPosition = p;
>>>>>        },
>>>>>        [](auto&...) { }
>>>>>      }, node);
>>>>>      return node;
>>>>>    }
>>>>>
>>>>> (This kind of stuff is all over the place, because it eliminates a LOT of redundant code)
>>>>
>>>> Huh? The design feels odd indeed.
>>>> I have usually stuff in variants that have rare things if anything
>>>> at all in common.
>>>
>>> Consider what the function does: it's checking (statically) if the struct has a particular member and setting it.
>>
>> Do not let complex syntax to confuse you ... magic does not exist.
>> It can't. It generates switch-case that checks *dynamically* behind scenes
>> what of those 68 is in that particular variant instance "node" and then
>> sets the member.
> 
> I'm not confused. The determination of whether a struct has a member is done statically via SFINAE. Specifically `decltype(n.exposedPosition)* = nullptr`. Of course *which* struct is of course dynamic.

I, on the other hand, am confused.

I remember reading the original blog posting (on a blog by some 
"experts", I think Dave Abrahams was there) about functionality like 
`overloaded`, to make a set of lambdas available via a single function 
that dispatches to them as if with overload resolution.

But now I fail to see, I don't remember, quite how it worked.

As I see it the OP shouldn't assume that readers would be familiar with 
`overloaded`.

When I can't imagine it and only vaguely remember reading about it, then 
I think most regulars here know just as little about it as I. And 
delving into links to third party web pages. Well that's just not done. :)


[snip]

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

issues with std::variant wtholliday@gmail.com - 2019-12-04 08:37 -0800
  Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-04 10:26 -0800
    Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-04 11:07 -0800
      Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-04 12:31 -0800
        Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-04 13:09 -0800
          Re: issues with std::variant "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-04 22:39 +0100
            Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-04 16:18 -0800
              Re: issues with std::variant "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-05 05:13 +0100
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 09:59 -0800
                Re: issues with std::variant Christian Gollwitzer <auriocus@gmx.de> - 2019-12-06 09:39 +0100
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-06 09:12 -0800
          Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-04 14:46 -0800
            Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-04 16:28 -0800
              Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-05 00:00 -0800
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 00:48 -0800
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-05 08:17 -0800
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 09:44 -0800
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-05 11:14 -0800
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 12:37 -0800
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-05 13:20 -0800
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 13:42 -0800
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-05 15:41 -0800
                Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-06 09:44 -0800
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-07 04:43 -0800
                Re: issues with std::variant Manfred <noname@add.invalid> - 2019-12-07 18:17 +0100
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-07 11:45 -0800
                Re: issues with std::variant Christian Gollwitzer <auriocus@gmx.de> - 2019-12-06 09:58 +0100
                Re: issues with std::variant Öö Tiib <ootiib@hot.ee> - 2019-12-06 06:06 -0800
  Re: issues with std::variant David Brown <david.brown@hesbynett.no> - 2019-12-04 22:34 +0100
    Re: issues with std::variant Vir Campestris <vir.campestris@invalid.invalid> - 2019-12-05 15:07 +0000
      Re: issues with std::variant Taylor <wtholliday@gmail.com> - 2019-12-05 10:01 -0800
      Re: issues with std::variant David Brown <david.brown@hesbynett.no> - 2019-12-05 22:15 +0100

csiph-web