17,333 questions
3
votes
1
answer
142
views
Conditional operator with a throwing branch in Visual C++ 2026
My program changed its behavior after updating Visual Studio to the latest version (2026).
Simplifying it, I got the following minimal example, which contains a ternary operator with a throw in ...
3
votes
1
answer
214
views
Use decltype(auto) return type to sometimes return references
I have the following code to normalize std::filesystem::path to always use forward slashes as separators:
static decltype(auto) fix_path_separator(const std::filesystem::path& path) {
if ...
1
vote
1
answer
109
views
Use a reference to $a to make $a a reference to $b
I have an array $arr = ['a', ['b',['c','d','e']]];.
So $arr[1][1][0] is 'c'.
I have these indexes listed in n array: $idx = [1,1,0];
(this may sound tricky, but comes from the fact that I got them ...
0
votes
1
answer
76
views
How to assign a new object to a reference?
Why can't I do it like this in Go?
func do(m1 map[int]string) {
var m map[int]string = make(map[int]string)
*m1 = &m;
}
I have m1 map, which means I can now it's reference? How to assign ...
1
vote
1
answer
128
views
Avoiding double references in Rust
I have the following utility method to get raw bytes of an object (to send via network, etc.):
pub fn to_bytes<T>(data: &T) -> &[u8] {
unsafe { slice::from_raw_parts((data as *...
5
votes
1
answer
183
views
Segmentation fault when trying to assign a global variable to a static reference variable
The following program gives segmentation fault.
#include <iostream>
using namespace std;
class A {
public:
static int& a;
};
int a = 42;
int& A::a = a;
int main() {
a = 100;
...
0
votes
0
answers
119
views
Making sense of const rvalue reference [duplicate]
I'm trying to understand the rvalue references in C++. Here's what I think they represent.
Say we have an object, O. This object exists on the stack and has the name O. This makes this object a lvalue....
0
votes
0
answers
62
views
The mutable reference I return from a function in Rust seems to violate the borrowing rules — how is this possible? [duplicate]
I have a mutable variable and a mutable reference to it. When I pass this reference to a function and return it back from there, it seems to violate Rust’s borrowing rules. What’s the reason for this?
...
2
votes
1
answer
169
views
c++20 tuple compare with reference
We upgrade our codebase from c++17 to c++20 lately, and some code does not work as before. I take the following simplified sample code as show case here.
None of the overloaded compare operators is ...
1
vote
2
answers
116
views
Creating virtual object in constructor initialization
I want to create a variable of type Foo. The class Foo consists of a variable called Bar bar_ which is filled directly in the constructor initialization. The thing is, class Bar has a reference to the ...
1
vote
1
answer
90
views
Simplifying getting a specific type from an enum
I have a set of classes linked into an enum:
#[derive(Default)]
pub struct A {
}
#[derive(Default)]
pub struct B {
}
#[derive(Default)]
pub struct C {
}
enum Classes {
A(A),
B(B),
C(C),
...
5
votes
2
answers
315
views
Can an rvalue of a specific class type be automatically cast to an lvalue of itself?
In C++, a function with signature void f(A& a) (non-template) only binds to a lvalue.
Is it possible for an rvalue to automatically cast itself to an lvalue?
This is what I tried:
#include <...
12
votes
1
answer
297
views
C++ temporary objects and constant reference
I am going through "C++ Primer", and it is mentioned that for the following code:
double dval = 3.14;
const int &ri = dval; //Bind a const int to a plain double object.
The ...
0
votes
1
answer
83
views
How to reference a second Pandas dataframe to the first one without creating any copy of the first one?
I have a large pandas dataframe df of something like a million rows and 100 columns, and I have to create a second dataframe df_n, same size as the first one. Several rows and columns of df_n will be ...
28
votes
1
answer
2k
views
Why is `&self` allowed in the parameters of `&mut self` methods, but not `&mut self`?
Rust method calls are desugared to fully-qualified-syntax and function parameters are evaluated left to right. Why then does s.by_mut(s.by_ref(())) compile while other
expressions don't?
struct S;
...
0
votes
2
answers
95
views
How can the italicized text be referenced in other cells?
I asked a question about italicizing specific parts of a cell (Making variable strings of text italics in Excel VBA).
I run the macro in column N to get what I want italicized, but when I reference ...
3
votes
1
answer
130
views
pybind11: Python callback executed in C++ with parameter modification
I'm working on Python bindings of my C++ library (a mathematical optimization solver) and I'm stuck at a point where I create a Python callback evaluate_constraints() that takes two arguments, pass it ...
0
votes
0
answers
127
views
Is it legal to take a pointer to a reference? [duplicate]
Is it legal and acceptable to take a pointer from a reference?
The following code compiles and work as one might expect, so I assume it is a legal construct. However, it feels wrong to take the ...
1
vote
1
answer
79
views
What are the basic rules for propagating lists and dictionaries across processes using the Manager of the multiprocessing module?
I am trying to use the multiprocessing module to parallelize a CPU-intensive piece code over multiple cores. This module looks terrific in several respects, but when I try to pass lists and ...
1
vote
1
answer
97
views
Any way to create a bitfield reference wrapper in a generic way?
I am creating wrappers for C structs containing register definitions with heavy use of bitfields. I would like to create reference getters for all of them, to provide consistent shorthand API (real ...
0
votes
0
answers
109
views
Lost name reference when setting extra attribute
I have shot myself in the foot a fair number of times with declare until I started to differentiate its switches that are not all equal. Some set variable attributes, but some just affect scope. So ...
0
votes
0
answers
32
views
VisualStudio 2022 CodeLens show references changed by itself
I've just noticed that my alt+2 hotkey for opening CodeLens show references window I've been using for years changed to alt+3. This happened only on my PC, on my laptop it's still on alt+2. There is ...
0
votes
1
answer
148
views
References name conflict across functions?
There's some interesting shenanigans going on with references:
#!/bin/bash
read -r -d '' payload << EOF
apple: vinegar
orange: juice
EOF
populate() {
declare -n _aa=$1
declare data=&...
-1
votes
2
answers
215
views
How to deserialize ${aa[@]@K} into referenced associative array with no eval effect?
How can I reference an associative array and reassign its content from serialized string?
(The eval requirement is now spelled out explicitly in the title, but this is natural when it comes to ...
2
votes
1
answer
84
views
Reference an open Excel file from PowerPoint using VBA [duplicate]
I found the following VBA code for PowerPoint which works and allows PowerPoint to reference an Excel file
Private Sub test()
Dim xlApp As Object
Dim xlWorkBook As Object
Set xlApp = CreateObject(&...
-5
votes
1
answer
78
views
What’s the mechanism that makes destructuring & rest parameter create an isolated copy, while rest parameter expose the original array to mutation?
function t(..._a)
{
console.log("t says:", _a[0] === a); // Output: t says: true
}
function v([..._a])
{
console.log("v says:", _a === a); // Output: v says: ...
0
votes
2
answers
149
views
Behavior is different when using the input "reference" variable, compared to when the same reference is copied
The Minimal Example that reproduces the issue is as follows:
#include <iostream>
#include <string>
#include <list>
#include <iterator>
#include <vector>
#include <...
1
vote
0
answers
18
views
Will passing an HTML reference to a React Custom Hook cause performance issues if the hook runs a lot? [duplicate]
I understand I can pass a reference to an HTML element to my React custom hook in react such as following:
let myCustomHook(elem:React.RefObject<any>) {
// logic
}
However, passing by reference ...
3
votes
1
answer
208
views
Why can a mutable reference variable be mutated-through even when it itself is not declared mut?
I have recently started learning Rust from The Book.
While learning about ownership, I came up with following piece of code:
let mut s = String::from("hello");
let r1 = &mut s;
Here it ...
3
votes
1
answer
112
views
When comparing a value and a reference, should I dereference the reference or create a reference to the value?
I'm trying to learn Rust and I managed to find two ways to solve a question (which was to convert from celsius to fahrenheit).
fn convert_only_if_needed(celsius_temp : &f64) -> f64 {
if !(*...
0
votes
1
answer
159
views
Delphi, referenching a TabSheet from another Tabsheet of a pagecontrol
On my main form (frmMain) I host a (Konopka) PageControl (TRzPageControl named pgcMain) with a tabsheet created at design time (pgDashboard). I created at frmMain.Create a dynamic form frm : ...
1
vote
0
answers
45
views
Do non-static fields of a const lvalue reference type extend the lifetime of a temporary? [duplicate]
Initially, to me the answer was obvious. However, I've come across an answer explaining binding temporaries to constant lvalue references which states the following:
This only applies to stack-based ...
1
vote
2
answers
113
views
What is the semantic difference in Rust between defining and initializing an instance of a structure and a reference to structure?
What is the semantic difference between defining and initializing an instance of a structure and a reference to structure? In other words, what's the difference in Rust between these two programs?
...
3
votes
2
answers
196
views
How to understand "constness is shallow" with regard to references (as stated in cppreference.com)?
While studying the cppreference spec of std::atomic_ref, I found myself brooding over the following sentence:
Like references in the core language, constness is shallow for std::atomic_ref - it is ...
0
votes
1
answer
64
views
Unresolved reference: ViewModelScope
I'm trying to run the example program at https://developer.android.com/kotlin/coroutines#examples-overview in Android Studio Iguana:
import androidx.lifecycle.ViewModel
import kotlinx.coroutines....
0
votes
0
answers
45
views
PHP foreach loops with references - wierd behaviour [duplicate]
Im currently developing a webpage and during that i wrote some code that looks similar to this:
$foo = ['bar1', 'bar2', "bar3"];
foreach($foo as $i => &$bar){
if($bar == "...
1
vote
1
answer
91
views
Is an FnMut argument a reference?
I've been trying to understand closures better. I originally wrote
fn main() {
let mut x = 0;
let f = || x += 1;
call_me(f);
f();
println!("x = {x}");
}
fn call_me<F&...
1
vote
2
answers
1k
views
Is it possible to reference .NET Framework 4.8 libraries in a .NET 8 project?
I'm working with an older C# solution built on .NET Framework 4.8, which contains several libraries. Now, I'm developing a new solution targeting .NET 8 that needs to reuse some of those existing ...
0
votes
0
answers
42
views
Issue with project references between MSTest and ConsoleApp in Visual Studio 2022
I'm facing a problem with setting up project references between an MSTest project and a ConsoleApp in Visual Studio 2022. The MSTest project is not correctly recognizing or linking to the ConsoleApp ...
0
votes
0
answers
33
views
How to correctly implement back references to parent objects in Rust [duplicate]
I have been working on a DOM object in Rust and to insure document integrity I want to implement back references to parent objects, prevent circular references, etc.
Minimally my code looks like this:
...
0
votes
1
answer
94
views
I've encountered a problem regarding referencing multiple versions of a DLL
I've encountered a problem regarding referencing multiple versions of a DLL. I've tried various methods to solve it. I'm seeking help.Thanks!
In a program, I referenced the DLL component of version 13....
2
votes
0
answers
55
views
JS HTMLImageElement and garbage collection
Am I required to hold ref to HTMLImageElement to prevent it from being gc'ed befor its load/error events will be fired?
for example:
/**
* @param { string[] } urls
* @returns { Promise<...
2
votes
1
answer
104
views
Why does std::span::operator[] not implement a const reference?
When writing:
std::vector<double> vec{1.0,2.0};
std::span<const double> s(vec);
s[0]=1.0;
I get a compiler error, as expected:
Cannot assign to return value because function 'operator[]' ...
2
votes
1
answer
104
views
How *actually* does this type-conversion argument-passing happen in this function call in C++
I'm trying to figure out how C++ actually breaks down the argument-passing when the formal argument is a reference and the actual argument is of a type that requires type-conversion.
Here's an ...
3
votes
1
answer
135
views
PHP variable as reference
I'm confused about the concept of variable in PHP.
As far as I know, a variable in PHP has a name ($p) and a value ('Carlo').
$p has an associated entry in symbol table, such an entry actually points ...
0
votes
0
answers
43
views
Why and how do I use Parameter References in C++? [duplicate]
I have no idea how to use them and why do we even need them
But when i try to solve some computer problems it came out that i can simplify my program using referance, so can you show me an example of ...
0
votes
1
answer
95
views
Delete ranges with openpyxl and adapt the relative references in formulae in the remaining cells
With openpyxl, when I use worksheet.move_range(range, rows=12, translate=True) the range will be moved 12 rows down. The translate=True will move the relative references in formulae in the range by ...
1
vote
0
answers
86
views
Passing a reference to a constructor causes runtime exception [duplicate]
I refactored some code and now my unit test is crashing. The code being tested runs fine in the project, but when I inherit from the class in the test fixture there is an error when running the ...
0
votes
0
answers
37
views
Referring to the variable being assigned to on the right side of the assignment operator
Sometimes it may be necessary (yes, likely against best practices) to deal with nested objects, such as lists, which can require multi-level indexation. I am curious of the following:
1. In Python, is ...
0
votes
0
answers
42
views
Cannot borrow `*self` as mutable more than once at a time [duplicate]
The Error
error[E0499]: cannot borrow `*self` as mutable more than once at a time
--> src\scanner\mod.rs:103:17
|
45 | impl<'a> Scanner<'a> {
| -- lifetime `'a` defined ...