What is the result type of ‘?:’ (ternary/conditional operator)?

Expressions don’t have return types, they have a type and – as it’s known in the latest C++ standard – a value category. A conditional expression can be an lvalue or an rvalue. This is its value category. (This is somewhat of a simplification, in C++11 we have lvalues, xvalues and prvalues.) In very broad … Read more

When should I use pointers instead of references in API-design?

Use references wherever you can, and pointers wherever you must. Avoid pointers until you can’t. The reason is that pointers make things harder to follow/read, less safe and far more dangerous manipulations than any other constructs. So the rule of thumb is to use pointers only if there is no other choice. For example, returning … Read more

Open matAutocomplete with open openPanel() method

The Material documentation should be clearer. Whilst there are various gymnastic routines you can do to achieve this functionality (like manipulating the document object, using @ViewChild, or creating event listeners), for me it boils down to the two following ways: 1 Minimalist: <mat-form-field> <input #nameInput matInput formControlName=”name” #trigger=”matAutocompleteTrigger” [matAutocomplete]=”autoName”> <mat-autocomplete #autoName=”matAutocomplete”> <mat-option *ngFor=”let o of … Read more

How can I get a reference to a method?

You want Object#method: ———————————————————- Object#method obj.method(sym) => method ———————————————————————— Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj’s object instance, so instance variables and the value of self remain available. class Demo def initialize(n) @iv = n end … Read more

Push to array reference

It might help to think in terms of memory addresses instead of variable names. my @a = (); # Set aside memory address 123 for a list. my $a_ref = [@a]; # Square brackets set aside memory address 456. # @a COPIES the stuff from address 123 to 456. push(@$a_ref,”hello”); # Push a string into … Read more

Why do these two string comparisons return different results?

Because the == is doing a reference comparison. With the C# compiler all the “equal” strings that are known at compile time are “grouped” together, so that string a = “abc”; string b = “abc”; will point to the same “abc” string. So they will be referentially equal. Now, (“ab” + “c”) is simplified at … Read more

Visual Studio 2010: Reference Assemblies Targeting Higher Framework Version

Step1: Unload the referencing project targeting .NET 2.0 Step2: Right click the unloaded project and select edit from context menu Step3: Add <SpecificVersion>true</SpecificVersion> to the reference. Below is a sample from my repro solution: <ProjectReference Include=”..\HighFX\HighFX.csproj”> <Project>{8DD71CAF-BEF7-40ED-9DD0-25033CD8009D}</Project> <Name>HighFX</Name> <SpecificVersion>true</SpecificVersion> </ProjectReference> Step4: Reload the project. Now your should be able to build within the Visual Studio … Read more

How are Kotlin Array’s toList and asList different?

TL;DR The list created with asList keeps a reference to the original Array. The list created with toList/toMutableList is backed by a copy of the original Array. Explanation asList The asList function creates a list that reuses the same Array instance, which implies that changes to the original array also have impact on the List: … Read more