182 questions
Score of 1
1 answer
181 views
error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive] [duplicate]
I'm trying to compile the following code:
#include <stdio.h>
#include <variant>
int main()
{
enum class TokenType {
FOO,
BAR,
};
using ConstTokenValue =...
Score of 10
0 answers
432 views
Convoluted operator<=> rules in case of mutually recursive std::variant
Coming from C++17 and trying to integrate operator<=>. I've stumbled on a conundrum. There seems to be no way to implement a generic container-like class where its T is a mutually recursive std:...
Advice
0
votes
9
replies
203
views
map enum values to data types
Is it possible to map the enum values to underlaying data types to use them with std::variant?
I want to do something like the example below, but want the std::variant to understand it is an int or ...
Score of 0
2 answers
194 views
cannot use static_assert for unsupported type
I'm trying to use code as below, but I am getting compilation errors.
The goal here is to have the "unsupported type in visitor triggered at compile time when a D is passed to visitor. Can ...
Score of 0
0 answers
93 views
Is it possible to add a std::variant as a component to an entity in EnTT?
I have different enums to specify the type of an object. I then use std::variant as an entity can be of any type, i.e.
enum Type1{
type1a,
type1b
};
enum Type2{
type2a,
type2b
};
...
Score of 2
2 answers
171 views
std::visit for QObject's
I have the following code that does not compile with Qt 6.7.2 on Debian :
#include <QCoreApplication>
#include <iostream>
#include <variant>
class Foo : public QObject
{
...
Score of 2
2 answers
195 views
How to implement a runtime type switching class in C++
How to implement a class that dynamically switching types using std::variant in runtime?
I'm currently trying to create a class that can:
Store a value in a std::variant with configurable type ...
Score of 1
2 answers
155 views
Use of `std::variant` to select types after command prompt input, is that even possible?
I am at a very early stage in writing a C++ program replicating the most basic functions of the ls bash command.
I use the <filesystem> header.
The std::filesystem::directory_iterator and std::...
Score of 1
1 answer
122 views
Allowing different fundamental types to share the same memory location by using std::bit_cast instead of std::variant or union?
It's possible to store ints or floats in the same memory location using std::bit_cast (including ints larger than 2^24 i.e. they can't be stored as whole numbers in floats because the mantissa has too ...
Score of 1
2 answers
155 views
Weird result of std::variant
I'm struggling with an odd behavior of the below code. The problem is that output of this snippet is "double". But we have an int in lhs.
I dug for a while and figured out the compiler put a ...
Score of 1
1 answer
105 views
gcc 10 refuse implict conversions for std::variant constructor
for this simple code
#include <vector>
#include <variant>
#include <stdint.h>
using KFPGAData = std::variant<uint16_t>;
int main(int,char**)
{
int v = 10;
KFPGAData d =...
Score of 1
2 answers
129 views
Container of std::variant of callable objects with bound parameters w/o using dynamic memory
I want to store several different callable objects (different types) in a container (e.g. std::array) in order to invoke them later.
Each callable has the same return type and the same amount and type ...
Score of 2
2 answers
380 views
Get a compile-time index to a std::variant when visiting it? [duplicate]
I have a std::variant of possibly repeated types, and I would like to increment the active index of the variant.
Here is an example demonstrating what I would like to do:
template <typename... Ts&...
Score of 10
3 answers
5480 views
When and why should I use std::monostate instead of std::optional with an std::variant?
Let's say I am writing a class that passes a std::variant<A,B> to another class.
While I design the class, I decide I'd like to keep a copy of the last thing that was passed to that other class. ...
Score of 0
1 answer
124 views
What does this variant storage use the buffer array for?
I see this piece of code for implementing a C++ std::variant-like type. This class is used as the variant storage.
What does the buffer array stores?
alignas(Types...) unsigned char buffer[sizeof(...