variant

Is it necessary to assign a default value to a variant returned from a Delphi function?

∥☆過路亽.° 提交于 2019-12-04 04:03:46
Gradually I've been using more variants - they can be very useful in certain places for carrying data types that are not known at compile time. One useful value is UnAssigned ('I've not got a value for you'). I think I discovered a long time ago that the function: function DoSomething : variant; begin If SomeBoolean then Result := 4.5 end; appeared to be equivalent to: function DoSomething : variant; begin If SomeBoolean then Result := 4.5 else Result := Unassigned; // <<<< end; I presumed this reasoning that a variant has to be created dynamically and if SomeBoolean was FALSE, the compiler

Is there a way to reset a std::variant from a known alternative?

☆樱花仙子☆ 提交于 2019-12-04 01:35:17
I'm in the process of updating a codebase that is currently using a custom equivalent of std::variant to C++17 . In certain parts of the code, the variant is being reset from a known alternative, so the class provides a method that asserts that index() is at a current value, but still directly invokes the proper destructor unconditionally. This is used in some tight inner loops, and has (measured) non-trivial performance impact. That's because it allows the compiler to eliminate the entire destruction when the alternative in question is a trivially destructible type. At face value, it seems to

Color Swatch / Variant dropdown list for shopify products

霸气de小男生 提交于 2019-12-03 17:15:58
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 got around to getting what I needed. so here I am for a little bit of help. Here's my variant list:

Excel VBA: Variants in Array Variables

耗尽温柔 提交于 2019-12-03 10:36:22
A question on variants. Im aware that variants in Excel vba are both the default data type and also inefficient (from the viewpoint of overuse in large apps). However, I regularly use them for storing data in arrays that have multiple data types. A current project I am working on is essentially a task that requires massive optimistaion of very poor code (c.7000 lines)- and it got me thinking; is there a way around this? To explain; the code frequently stores data in array variables. So consider a dataset of 10 columns by 10000. The columns are multiple different data types (string, double,

check boost::variant<T> for null

十年热恋 提交于 2019-12-03 08:45:53
问题 I have a boost::variant in my program and I want to check if the variant itself is initialized and also if there is a value contained in one of it's types. I've tried empty() on the variant, but that doesn't seem to work. Neither does checking against NULL. Does anybody know how to check for this? EDIT: Ok, It seems it will never be empty, but there will not always be a value in it's contained types, so how do I check for a no-value situation? 回答1: A boost::variant is always initialized. If

How to build a SAFEARRAY of pointers to VARIANTs?

戏子无情 提交于 2019-12-03 07:47:02
I'm trying to use a COM component with the following method: HRESULT _stdcall Run( [in] SAFEARRAY(BSTR) paramNames, [in] SAFEARRAY(VARIANT *) paramValues ); How can I create in C/C++ the paramValues array? Adding to the answers above for reference by future readers: In IDL, SAFEARRAY(...) means a pointer to an array descriptor. But in C++, SAFEARRAY means an array descriptor. So IDL's SAFEARRAY(...) is really C++'s SAFEARRAY * . This confused me to no end. To make things even more interesting, VB always passes arrays by reference. So VB's () As Long is SAFEARRAY<int32_t> ** in C++. (I don't

Function which returns an unknown type

心不动则不痛 提交于 2019-12-03 06:55:18
class Test { public: SOMETHING DoIt(int a) { float FLOAT = 1.2; int INT = 2; char CHAR = 'a'; switch(a) { case 1: return INT; case 2: return FLOAT; case 3: return CHAR; } } }; int main(int argc, char* argv[]) { Test obj; cout<<obj.DoIt(1); return 0; } Now, using the knowledge that a = 1 implies that I need to return an integer, etc., is there anyway Doit() can return a variable of variable data type? Essentially, with what do I replace SOMETHING ? PS: I'm trying to find a an alternative to returning a structure/union containing these data types. You can use boost::any or boost::variant to do

How to make a safer C++ variant visitor, similar to switch statements?

核能气质少年 提交于 2019-12-03 06:38:31
问题 The pattern that a lot of people use with C++17 / boost variants looks very similar to switch statements. For example: (snippet from cppreference.com) std::variant<int, long, double, std::string> v = ...; std::visit(overloaded { [](auto arg) { std::cout << arg << ' '; }, [](double arg) { std::cout << std::fixed << arg << ' '; }, [](const std::string& arg) { std::cout << std::quoted(arg) << ' '; }, }, v); The problem is when you put the wrong type in the visitor or change the variant signature

Is there an existing name for this type and function?

走远了吗. 提交于 2019-12-03 05:40:54
问题 There are 2 hard problems in computer science: cache invalidation, naming things and off-by-one errors. This is about the 2nd problem: naming things. I'm looking if this technique or type has been used somewhere else already and has a name. dichotomy is an ok name, but bools_at_compile_time is a horrible one. using dichotomy_t = std::variant<std::false_type, std::true_type>; // (or a struct that inherits from that, and overloads operator bool()) constexpr dichotomy_t dichotomy( bool b ) { if

check boost::variant<T> for null

好久不见. 提交于 2019-12-02 22:36:15
I have a boost::variant in my program and I want to check if the variant itself is initialized and also if there is a value contained in one of it's types. I've tried empty() on the variant, but that doesn't seem to work. Neither does checking against NULL. Does anybody know how to check for this? EDIT: Ok, It seems it will never be empty, but there will not always be a value in it's contained types, so how do I check for a no-value situation? A boost::variant is always initialized. If you did not initalized it explicitly, the first item was constructed using its default constructor: struct