variant

Access std::variant inside lambda

时间秒杀一切 提交于 2020-06-01 05:49:50
问题 I have the following code: std::variant<std::uint32_t, std::uint16_t, float> my_variant; template <typename T> void my_sub_func(T& value) { // do stuff }; void my_func(my_variant& value) { [&]() { my_sub_func(std::get<std::uint32_t>(value)); }; }; int main() { my_variant t; my_func(t); } I always get an Unexpected index exception at runtime, why is that and how can I avoid it? 来源: https://stackoverflow.com/questions/61930744/access-stdvariant-inside-lambda

How to parse json file with type composition of std::optional and std::variant

谁都会走 提交于 2020-02-16 12:28:30
问题 How can I parse the input json inside this file, especially for the accuracy , secondary and flags properties? https://github.com/smogon/pokemon-showdown/blob/master/data/moves.js They are type composition of optional and variant . Though only the full example can surface the problem in a clearer way, a minimal starting point example would be this one: [ {}, { "secondary": false }, { "secondary": { "chance": 10, "boosts": { "spd": -1 } } }, { "secondary": { "chance": 30, "volatileStatus":

How does the caller know when there's a Decimal inside a VARIANT?

岁酱吖の 提交于 2020-02-04 01:18:05
问题 The COM VARIANT type is defined using the tagVARIANT structure like this: typedef struct tagVARIANT { union { struct { VARTYPE vt; WORD wReserved1; WORD wReserved2; WORD wReserved3; union { LONGLONG llVal; LONG lVal; BYTE bVal; SHORT iVal; FLOAT fltVal; DOUBLE dblVal; VARIANT_BOOL boolVal; VARIANT_BOOL __OBSOLETE__VARIANT_BOOL; SCODE scode; CY cyVal; DATE date; BSTR bstrVal; IUnknown *punkVal; IDispatch *pdispVal; SAFEARRAY *parray; BYTE *pbVal; SHORT *piVal; LONG *plVal; LONGLONG *pllVal;

When to use SafeArrayAccessData to lock a SAFEARRAY

旧街凉风 提交于 2020-01-24 18:58:39
问题 I'm having a question about when it is necessary to use SafeArrayAccessData to lock a SAFEARRAY, which is passed by managed code. Here is our code. The VARIANT is passed by managed code, with a string array. During code review, somebody suggest to use SafeArrayAccessData/SafeArrayUnAccessData. But he is not sure about why and what's the benefit. Can you share some of your experiences? Thanks! STDMETHODIMP Base::Method1(VARIANT values, VARIANT_BOOL result) { CComSafeArray<BSTR> ids; ids.Attach

std::variant and incomplete type: how does it work?

风流意气都作罢 提交于 2020-01-16 09:09:14
问题 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 holds. So, why does this code does not compile with s1 and s2 . How can make it works like std::variant ? #include <variant> #include <vector> #include <type_traits> #include <typeinfo> #include <iostream> struct Rect; struct Circle; using Shape = std::variant<Rect, Circle>; template<typename C> struct

Delphi Enums to Variant as varInteger instead of varUInt32

别来无恙 提交于 2020-01-15 09:21:30
问题 Delphi enumeration values are natively defined as unsigned integers - 1, 2 or 4 bytes, depending on the setting of MINENUMSIZE. I have a case where we are using Variants to transfer data of different data types between applications. All other data types work nicely, but now we realised that the expectation from other applications is that the enumerated values should be signed integers instead of unsigned (and some are really validating this). Is there a way to configure the automatic variant

Delphi Enums to Variant as varInteger instead of varUInt32

假如想象 提交于 2020-01-15 09:21:02
问题 Delphi enumeration values are natively defined as unsigned integers - 1, 2 or 4 bytes, depending on the setting of MINENUMSIZE. I have a case where we are using Variants to transfer data of different data types between applications. All other data types work nicely, but now we realised that the expectation from other applications is that the enumerated values should be signed integers instead of unsigned (and some are really validating this). Is there a way to configure the automatic variant

A simple way to convert to/from VARIANT types in C++

匆匆过客 提交于 2020-01-13 08:50:31
问题 Are there any easy-to-use , high-level classes or libraries that let you interact with VARIANT s in Visual C++? More specifically, I'd like to convert between POD types (e.g. double , long ), strings (e.g. CString ), and containers (e.g. std::vector ) and VARIANT s. For example: long val = 42; VARIANT var; if (ToVariant(val, var)) ... // tries to convert long -> VARIANT comObjPtr->someFunc(var); std::vector<double> vec; VARIANT var = comObjPtr->otherFunc(); if (FromVariant(var, vec)) ... //

Is there any hope to call a common base class method on a std::variant efficiently?

一曲冷凌霜 提交于 2020-01-12 03:11:07
问题 The way std::variant dispatches to different visitor methods when std::visit is called is pretty reasonable when the variant alternatives are completely different types. Essentially a visitor-specific vtable is built at compile-time and after some error checking 1 the appropriate visitor function is looked by indexing the table based the current index() which resolves to something like an indirect jump on most platforms. If the alternatives share a common base class, however, calling a (non

Is there any hope to call a common base class method on a std::variant efficiently?

▼魔方 西西 提交于 2020-01-12 03:11:04
问题 The way std::variant dispatches to different visitor methods when std::visit is called is pretty reasonable when the variant alternatives are completely different types. Essentially a visitor-specific vtable is built at compile-time and after some error checking 1 the appropriate visitor function is looked by indexing the table based the current index() which resolves to something like an indirect jump on most platforms. If the alternatives share a common base class, however, calling a (non