variant

Why am I getting “The type parameter must be invariantly valid…” error?

余生颓废 提交于 2019-11-29 10:32:11
I'll attempt to shorten this code example: public interface IThing { //... Stuff } public class Thing1 : IThing { } public class Thing2 : IThing { } public interface IThingView<out T> { ICollection<T> ViewAll(); } public class ThingView<T> : IThingView<T> { ICollection<T> ViewAll() { return new List<T>(); } // There's a big operation here } public interface IThingViewerFactory { public IThingView<IThing> Build(string Which); } public class ThingViewerFactory { public IThingView<IThing> Build(string Which) { if(Which.Equals("Thing1") { return new (IThingView<IThing>)new ThingViewer<Thing1>();}

Convert std::variant to another std::variant with super-set of types

天大地大妈咪最大 提交于 2019-11-29 10:13:43
I have a std::variant that I'd like to convert to another std::variant that has a super-set of its types. Is there a way of doing it than that allows me to simply assign one to the other? template <typename ToVariant, typename FromVariant> ToVariant ConvertVariant(const FromVariant& from) { ToVariant to = std::visit([](auto&& arg) -> ToVariant {return arg ; }, from); return to; } int main() { std::variant<int , double> a; a = 5; std::variant <std::string, double, int> b; b = ConvertVariant<decltype(b),decltype(a)>(a); return 0; } I'd like to be able to simply write b = a in order to do the

How to pass SAFEARRAY to COM object through IDispatch?

耗尽温柔 提交于 2019-11-29 04:33:22
i am trying to call a method of COM object, where one of the documented parameters is an "array of bytes ". The actual declartion depends on the per-language documentation you're looking at: in C# language: byte[] TransformFinalBlock( byte[] inputBuffer, int inputOffset, int inputCount ) in C++ language; array<unsigned char>^ TransformFinalBlock( array<unsigned char>^ inputBuffer, int inputOffset, int inputCount ) in VB language: Function TransformFinalBlock ( _ inputBuffer As Byte(), _ inputOffset As Integer, _ inputCount As Integer _ ) As Byte() in F# language: abstract TransformFinalBlock :

Can't stream std::endl with overloaded operator<<() for std::variant

╄→гoц情女王★ 提交于 2019-11-28 20:24:27
This answer describes how to stream a standalone std::variant . However, it doesn't seem to work when std::variant is stored in a std::unordered_map . The following example : #include <iostream> #include <string> #include <variant> #include <complex> #include <unordered_map> // https://stackoverflow.com/a/46893057/8414561 template<typename... Ts> std::ostream& operator<<(std::ostream& os, const std::variant<Ts...>& v) { std::visit([&os](auto&& arg) { os << arg; }, v); return os; } int main() { using namespace std::complex_literals; std::unordered_map<int, std::variant<int, std::string, double,

Variable iterating on itself - different behavior with different types

佐手、 提交于 2019-11-28 19:10:18
Please take a look at the latest updates at the end of the post. In Particular, see Update 4: the Variant comparison Curse I’ve already seen mates banging their head against the wall to understand how a variant works, but never imagined that I will have my own bad moment with it. I have successfully used the following VBA construction: For i = 1 to i This works perfectly when i is an Integer or any numeric type, iterating from 1 to the original value of i . I do this on occasions where i is a ByVal parameter - you might say lazy - to spare myself the declaration of a new variable. Then I had a

Variant datatype library for C

亡梦爱人 提交于 2019-11-28 13:34:05
Is there a decent open-source C library for storing and manipulating dynamically-typed variables (a.k.a. variants)? I'm primarily interested in atomic values (int8, int16, int32, uint, strings, blobs, etc.), while JSON-style arrays and objects as well as custom objects would also be nice. A major case where such a library would be useful is in working with SQL databases. The most obvious feature of such a library would be a single type for all supported values, e.g.: struct Variant { enum Type type; union { int8_t int8_; int16_t int16_; // ... }; }; Other features might include converting

How to pass an array of bytes reference to a COM object method

匆匆过客 提交于 2019-11-28 13:07:59
In PHP, I want to pass an array of bytes reference to a COM object method whose syntax in VB is: object.VBObjectMethod(ByRef aRawData() As Byte) where parameter aRawData is an array of bytes that specifies a data object. In PHP I am initialising the COM class and calling VBObjectMethod as follows: $theObject = new COM("VBObject.Class") or die ("Could not initialise VBObjectClass"); Up to this bit things are OK but I have no idea how to do the following correctly: $theObject->VBObjectMethod("How do I pass a reference to a byte array here?"); I have a $byteArray I am passing to VBObjectMethod in

Adding or multiplying variants in VBA

流过昼夜 提交于 2019-11-28 13:02:20
Suppose we are given two variants, X and Y , that may be numbers, ranges or arrays. Is there a simple way to add or multiply them like in worksheet formulas =X+Y and =X*Y ? One possibility i thought of would be to use the Evaluate operation, something like this: Dim X, Y Sub AddMult() Dim Add, Mult X = Array(Array(1, 3), Array(2, 4)) Y = Array(1, 2) Add = [GetX()+GetY()] Mult = [GetX()*GetY()] End Sub Function GetX() GetX = X End Function Function GetY() GetY = Y End Function It seems a little awkward though. Any other ideas? (Here is a related question: Multiplying arrays with scalars and

get<string> for variants fail under clang++ but not g++

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:57:06
问题 The following code: variant<string> x = "abc"; cout << get<string>(x) << "\n"; works fine under g++ (version 7.2). However, when compiled under clang++ (version 5.0) using libstdc++, I get the following error in the get method: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/variant:238:46: fatal error: cannot cast 'std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to its private base class 'std::__detail::__variant::

BSTR's and VARIANT's under… mac os x

孤街浪徒 提交于 2019-11-28 06:33:38
问题 Under mac os x I have office 2011 and its excel and VBA, and I have gcc-5.3.0's g++. I played a lot to passing arrays (of numerical built-in types) from VBA to the dylib (extension of dll's on mac os x) and updating them and sending them back to VBA, see for instance : passing c/c++ dylib function taking pointer to VBA on mac Now, I would like to do the same with strings, and first with just one string, not an array. I want to receive the string from VBA, modify it in C++, and send it back,