variant Questions
14
Solved
class Test
{
public:
SOMETHING DoIt(int a)
{
float FLOAT = 1.2;
int INT = 2;
char CHAR = 'a';
switch(a)
{
case 1: return INT;
case 2: return FLOAT;
case 3: return CHAR;
}
}
};
int m...
Galvanotropism asked 31/8, 2009 at 17:22
2
Solved
At work, I ran into a situation where the best type to describe the result returned from a function would be std::variant<uint64_t, uint64_t> - of course, this isn't valid C++, because you ca...
Tolerable asked 11/11, 2020 at 1:23
5
Solved
(Warning: Although it might look like one at first glance, this is not a beginner-level question. If you are familiar with the phrase "Let coercion" or you have ever looked into the VBA spec, pleas...
1
Solved
I'm trying to experiment with making a visitor with just a simple class, with overloads of operator() for each type in the variant.
I expected this to work (as it's how I assumed it worked fo...
Stoichiometry asked 6/10, 2020 at 13:31
2
Solved
I have defined the following variant:
std::variant<int, bool, MyType, int> myVar;
The type of the member at index 2 is MyType. How to get this during compile time? (so that I can use it in a...
10
Does anyone know how to return the number of dimensions of a (Variant) variable passed to it in VBA?
Adenoid asked 1/8, 2011 at 17:16
1
Solved
I just bounced into something subtle in the vicinity of std::visit and std::function that baffles me. I'm not alone, but the only other folks I could find did the "workaround and move on" dance, an...
Unpleasant asked 15/6, 2020 at 19:29
3
Solved
I am relatively new to CPP and have recently stumbled upon std::variant for C++17.
However, I am unable to use the << operator on such type of data.
Considering
#include <iostream>
...
Ernaernald asked 13/6, 2020 at 4:42
1
Solved
I have the JSON roughly like this:
[
{
"commonA": 1,
"commonB": 2,
"type": "Foo",
"fooSpecificA": 3,
"fooSpecificB": 4
},
{
"commonA": 5,
"commonB": 6,
"type": "Bar",
"barSpecificA": 7...
4
Solved
What's the easiest way to default construct an std::variant from the index of the desired type, when the index is only known at runtime? In other words, I want to write:
const auto indx = std::var...
Carranza asked 6/3, 2020 at 12:31
4
I have a specific build variant that is ONLY used for mock testing. I'd prefer not to run unit tests against this variant (but want to run them against other variants). Is there any way to inform g...
5
Solved
I'm trying to access the content of a variant. I don't know what's in there, but thankfully, the variant does. So I thought I'll just ask the variant what index it is on and then use that index to ...
2
Solved
I'm trying to create a std::vector that can hold std::function objects of different signatures using std::variant.
Why does the following code not compile:
#include <functional>
#include &l...
3
Solved
Consider the following code snippet:
struct v : std::variant<int, std::vector<v>> { };
int main()
{
std::visit([](auto){ }, v{0});
}
clang++ 7 with -stdlib=libc++ -std=c++2a compi...
Alvaroalveolar asked 12/7, 2018 at 15:28
2
Solved
I recently followed a Reddit discussion which lead to a nice comparison of std::visit optimization across compilers. I noticed the following: https://godbolt.org/z/D2Q5ED
Both GCC9 and Clang9 (I g...
3
Solved
The code below:
int i = 1;
const int i_c = 2;
volatile int i_v = 3;
const volatile int i_cv = 4;
typedef std::variant<int, const int, volatile int, const volatile int> TVariant;
TVariant...
2
I am trying to build and run this repository augmented-images
and I encounted this error.
Caused by: java.lang.RuntimeException: Error creating sfa.
Which drill down to this warning Warning ! API...
2
Solved
I have some variant using V = std::variant<A, B, C> and a function with the prototype V parse(const json&). The function should try to parse all the types (e.g. A, B, then C) till the fir...
Vo asked 24/8, 2019 at 23:6
1
Solved
I've been recently trying C++17's std::variant and std::visit, and I found it quite powerful.
I specially liked the ability to create a visitor pattern over several variant objects.
Here is one exa...
Graphite asked 21/8, 2019 at 19:41
1
Solved
I do understand that std::variant works with incomplete type. However, I don't understand how it can works because, in my understanding, std::variant must need the maximum size of the types it hold...
1
Solved
I would like to write a generic lambda as a visitor for a variant. The members of this variant contain a constexpr member value, which I would like to use in the visitor. For example:
#include <...
Feeler asked 10/7, 2019 at 8:38
1
Solved
I have this type:
struct immobile {
// other stuff omitted
immobile(immobile&) = delete;
immobile(immobile&&) = delete;
};
immobile mk_immobile();
// e.g. this compiles
// mk_immobi...
Sipple asked 4/6, 2019 at 0:12
2
Solved
I am building a state-machine where state transitions are described as a variant, i.e.:
using table = std::variant<
/* state event followup-state */
transition<start, success<sock>, c...
Saveloy asked 22/5, 2019 at 9:18
3
Solved
This is a followup on this answer.
Assume we have two types of std:variant with partly the same member types. For instance if we have
struct Monday {};
struct Tuesday {};
/* ... etc. */
using Week...
5
There are 2 hard problems in computer science: cache invalidation, naming things and off-by-one errors.
This is about the 2nd problem: naming things.
I'm looking if this technique or type has bee...
© 2022 - 2024 — McMap. All rights reserved.