variant

c++ variant class member stored by reference

我的梦境 提交于 2020-01-11 11:24:02
问题 I am trying to experiment with std::variant. I am storing an std::variant as a member of a class. In the below code, things work fine if the variant is stored by value, but does not work (for the vector case, and for custom objects too) if the variant is stored by reference. Why is that? #include <variant> #include <vector> #include <iostream> template<typename T> using VectorOrSimple = std::variant<T, std::vector<T>>; struct Print { void operator()(int v) { std::cout << "type = int, value =

c++ variant class member stored by reference

懵懂的女人 提交于 2020-01-11 11:23:11
问题 I am trying to experiment with std::variant. I am storing an std::variant as a member of a class. In the below code, things work fine if the variant is stored by value, but does not work (for the vector case, and for custom objects too) if the variant is stored by reference. Why is that? #include <variant> #include <vector> #include <iostream> template<typename T> using VectorOrSimple = std::variant<T, std::vector<T>>; struct Print { void operator()(int v) { std::cout << "type = int, value =

How can I convert a string array to a variant array in VBscript?

大兔子大兔子 提交于 2020-01-11 09:51:53
问题 I'm using a function in vbscript which returns a variant array of strings. JobIDs = objDoc.ConnectedSubmit(objServer) The problem is I can't get the Job ID values from that array, as vbscript doesn't handle typed variables. It just gives a type mismatch when I attempt to do ANYTHING with the JobIDs array. I found some promising information here, but when I used the conversion function: Set objConverter = CreateObject("ADS.ArrayConvert") ConvertedJobIDs = objConverter.CStrArray(JobIDs()) It is

How can I convert a string array to a variant array in VBscript?

眉间皱痕 提交于 2020-01-11 09:51:31
问题 I'm using a function in vbscript which returns a variant array of strings. JobIDs = objDoc.ConnectedSubmit(objServer) The problem is I can't get the Job ID values from that array, as vbscript doesn't handle typed variables. It just gives a type mismatch when I attempt to do ANYTHING with the JobIDs array. I found some promising information here, but when I used the conversion function: Set objConverter = CreateObject("ADS.ArrayConvert") ConvertedJobIDs = objConverter.CStrArray(JobIDs()) It is

What is boost::variant memory and performance cost?

大憨熊 提交于 2020-01-10 18:14:08
问题 boost::variant seems a powerful container to manipulate a heterogeneous set of types. I am wondering its cost. In memory, I think it takes up the size of the largest type plus an integer representing which(). For apply_visitor(), I think its performance is very good, it can call directly the function other than lots of ifs. Are my points right? 回答1: You're almost right. The size of boost::variant is is the max size of any element, rounded up as needed for the largest alignment , plus the size

What is boost::variant memory and performance cost?

巧了我就是萌 提交于 2020-01-10 18:12:57
问题 boost::variant seems a powerful container to manipulate a heterogeneous set of types. I am wondering its cost. In memory, I think it takes up the size of the largest type plus an integer representing which(). For apply_visitor(), I think its performance is very good, it can call directly the function other than lots of ifs. Are my points right? 回答1: You're almost right. The size of boost::variant is is the max size of any element, rounded up as needed for the largest alignment , plus the size

Variant type storage and alignment issues

让人想犯罪 __ 提交于 2020-01-07 07:46:29
问题 I've made a variant type to use instead of boost::variant. Mine works storing an index of the current type on a list of the possible types, and storing data in a byte array with enough space to store the biggest type. unsigned char data[my_types::max_size]; int type; Now, when I write a value to this variant type comes the trouble. I use the following: template<typename T> void set(T a) { int t = type_index(T); if (t != -1) { type = t; puts("writing atom data"); *((T *) data) = a; //THIS PART

Passing a VARIANT from mac OS X Excel 2011 VBA to c++

早过忘川 提交于 2020-01-07 01:22:13
问题 I am under mac OS X, and using excel-2011 vba. I know how to pass various types from VBA to c++ and inversely, mainly thanks to this. Now, I would like to know if it is possible to somehow pass a VBA variant to c++ (I am using gcc 5.2). Of course, there's no VARIANT in gcc but, after all, VARIANT is "just" a union. (The optimistic guy.) Have you guys heared about classes mimicking microsoft's VARIANT and allowing to achieve this ? (In the first time, I could accept to forget about IUnknown

C++17 using std::variant to represent DOM

时光总嘲笑我的痴心妄想 提交于 2020-01-06 04:32:24
问题 I'm trying to learn how to use std::variant from C++17. As an example started using it, to represent the DOM. Though this is still work in progress: I wanted to get expert opinion on the usage of std::variant also some inputs on the compiler support. I've the DOM representation code (Godbolt's Compiler Explorer link) and it seems to compile fine with Clang trunk. However, I see that the same code does not compile with GCC 8.0.0 20171009. I would like to understand what is the reason for this

Insert raw file data into BLOB (“OLE Object”) field of Access table using ADO

[亡魂溺海] 提交于 2020-01-04 12:48:12
问题 I am trying to insert a file into MS Access database, into a field of OLE Object type. I am using C++ and ADO . Currently I get error Invalid pointer error . I think that my problem is mishandling variants since this is the first time I use them. I am learning from this code example but have problem understanding how to insert file from disk into variant . They read it from database, and copied it into new record so the part where I read file from disk and then insert it into variant is