variant

VARIANT datatype of C++ into C#

人走茶凉 提交于 2019-12-06 21:06:51
问题 What is equivalent of the VARIANT datatype of C++ in C#? I have code in C++ which uses the VARIANT datatype. How can I convert that code in C#? 回答1: This is a tricky question. From C# 4, you can use dynamic to indicate that the type is known at run-time. By my personal understanding, however, c++ requires the type known at compile time. Thus you might consider to use object , but object in C# is an existent type. For the concept of multi-type, single value (AKA polymorphism) of VARIANT, you

How can I marshall between XLOPER and VARIANT? [closed]

坚强是说给别人听的谎言 提交于 2019-12-06 07:01:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm working on an Excel plugin (XLL), which communicates with COM objects. So, I have to marshall between XLOPER and VARIANT. I've got most of this working, but arrays are definitely a pain. I need to support 1- and 2D arrays. I imagine someone has already had to deal with this before. What's the best way to

How to define a variant<x,y,z> extracting subtypes of a template parameter

风流意气都作罢 提交于 2019-12-06 06:42:13
问题 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>, connecting>, transition<start, exception, failed>, transition<connecting, success<>, connected>, transition<connecting, exception, failed>, transition<connected, exception, failed> >; and transition being a simple type: template <typename ENTRY_STATE, typename EVENT, typename NEXT_STATE> struct transition { using

Does something like a VB “Variant” implementation exist which uses C#'s dynamic dispatch?

不羁岁月 提交于 2019-12-06 02:03:44
I realize that it goes against the strongly typed nature of C#, but I find that when working with dynamic objects in the language, some of the more useful features typically found in JavaScript or PowerShell are simply not practical. For example, the following C# code will fail at runtime and it's obvious why. dynamic x = 1.0; int y = x; But that makes the dynamic features of C# pretty limited when dealing with loosely typed data such as that produced by JSON payloads or CSV where subtle variations in the representation can result in very different behavior at runtime. What I'm looking for is

Sending and receiving arrays over COM

霸气de小男生 提交于 2019-12-05 23:22:07
What is the right way to receive and send arrays over COM? Here's my attempt so far: a safearray of doubles wrapped in a variant. //takes variant holding safearray of doubles //returns a similar variant having multipled every element by 2 STDMETHODIMP MyComClass::safearraytimestwo(VARIANT in, VARIANT* out) { CComSafeArray<double> sa_in; sa_in.Attach(*in.pparray); ULONG size = sa_in.GetCount(); CComSafeArray<double> *out_sa = new CComSafeArray<double>(size); for (long i=0;i<size;i++) out_sa->SetAt(i,sa_in[i]*2); out = new CComVariant(out_sa); return S_OK; } Problems: - currently compilation

vba-variant: how to handle Class vs. primitive types

拟墨画扇 提交于 2019-12-05 21:02:38
my function gets a collection and the items may be Objects or primitives how can I assign the item to a variant? What I do now looks something like this: Dim vItem As Variant On Error Resume Next vItem = oCollection.Item(sKey) If Err.Number = 91 Then Set vItem = oCollection.Item(sKey) On Error GoTo 0 I think it works, but I wonder if there is a better way to do it. SWa You may use the varType() function to test the type, alternatively if you are testing for specific types, you could use typeof. If VarType(oCollection.Item(sKey)) = vbObject Then Set vItem = oCollection.Item(sKey) Else vItem =

Iterator for boost::variant

六眼飞鱼酱① 提交于 2019-12-05 12:03:07
Hy there, I'm trying to adapt an existing code to boost::variant. The idea is to use boost::variant for a heterogeneous vector. The problem is that the rest of the code use iterators to access the elements of the vector. Is there a way to use the boost::variant with iterators? I've tried typedef boost::variant<Foo, Bar> Variant; std::vector<Variant> bag; std::vector<Variant>::iterator it; for(it= bag.begin(); it != bag.end(); ++it){ cout<<(*it)<<endl; } But it didn't work. EDIT: Thank you for your help! But in my design, I need to get one element from the list and pass it around other parts of

Return type std::optional<std::variant<…>>

我怕爱的太早我们不能终老 提交于 2019-12-05 05:36:24
I have a situation where a function must return a value taken from a table. A cell in this table (let's assume the table just works...) may contain a value, or it might not. This value can also be one of several types: int, double, string, date (but no other type). What would such a function return? Is it a good idea to return std::optional<std::variant<std::string, int, double, std::chrono::time_point>> ? Would that be a good use of optional and variant ? I would consider this to be a useful use of std::monostate . Specifically, variant<std::monostate, int, double, std::string, std::chrono:

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

落花浮王杯 提交于 2019-12-05 05:35:38
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)) ... // tries VARIANT -> std::vector<double> I (naively?) assumed that people working with COM do this all the

Color Swatch / Variant dropdown list for shopify products

时光毁灭记忆、已成空白 提交于 2019-12-05 03:26:24
问题 What I intend to do is to do a dropdown list for the product 'color' variant, however with some sort of association with the option value, an image swatch or jpg is displayed. I found this tutorial to do association of color swatches with product color choice. However, this displays variants in a button form instead of the defaul dropdown. http://docs.shopify.com/manual/configuration/store-customization/add-color-swatches-to-your-products I've been messing about with the scripts but I never