std-variant Questions

3

Solved

std::variant can enter a state called "valueless by exception". As I understand, the common cause of this is if a move assignment throws an exception. The variant's old value isn't guaran...
Impaction asked 28/8, 2019 at 15:55

3

Solved

C++17 presents std::variant and std::any, both able to store different type of values under an object. For me, they are somehow similar (are they?). Also std::variant restricts the entry types, be...
Campaign asked 25/5, 2019 at 10:25

1

Solved

With C++14, I'm using boost::variant as a way of compile-time polymorphism: using MyType = boost::variant<A, B>; Both classes have a method sayHello(). I'd like to call: MyType obj = ...;...
Minnie asked 17/5, 2019 at 9:51

1

Solved

Does the following code invoke undefined behaviour? std::variant<A,B> v = ...; std::visit([&v](auto& e){ if constexpr (std::is_same_v<std::remove_reference_t<decltype(e)>,...
Piemonte asked 15/3, 2019 at 17:5

2

Solved

I've migrated from boost::variant to std::variant, and hit a snag. I was using a nice function in boost 'type()' that lets you get the currently held typeid. See https://www.boost.org/doc/libs/1_...
Hasan asked 9/12, 2018 at 21:11

1

Solved

Consider this example on Compiler explorer. Basically, we have this code snippet: #include <cstdint> #include <variant> enum class Enum1 : std::uint8_t { A, B }; enum class Enum2 : ...
Triumvir asked 8/12, 2018 at 19:38

3

Solved

I a trying to make a std::variant that can contain a vector of the same variant: class ScriptParameter; using ScriptParameter = std::variant<bool, int, double, std::string, std::vector<Scrip...
Enwreathe asked 27/11, 2018 at 15:18

1

Solved

With the following code how do I write the custom template deduction correctly? template<class R, class State, class... Ts> struct visitor : Ts... { using Ts::operator()...; }; template<cl...
Wise asked 24/11, 2018 at 20:58

1

Solved

I want to have a variant which may contain type Foo, (disjoint) type Bar, or nothing. Well, naturally, I was thinking of using std::variant<Foo, Bar, void> - but this doesn't seem to work. Th...
Carltoncarly asked 2/11, 2018 at 22:24

© 2022 - 2024 — McMap. All rights reserved.