Skip to main content
3 votes
1 answer
208 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 ...
Dominik Kaszewski's user avatar
1 vote
1 answer
100 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 ...
fpierrat's user avatar
  • 818
0 votes
1 answer
75 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 ...
Pasha's user avatar
  • 1,988
1 vote
1 answer
113 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 *...
Alexander's user avatar
  • 641
5 votes
1 answer
178 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; ...
Keshav Saraf's user avatar
0 votes
0 answers
117 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....
Setu's user avatar
  • 1,086
0 votes
0 answers
60 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? ...
Enes's user avatar
  • 9
2 votes
1 answer
162 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 ...
newID's user avatar
  • 343
1 vote
2 answers
112 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 ...
peter's user avatar
  • 59
1 vote
1 answer
89 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), ...
Alan Birtles's user avatar
5 votes
2 answers
309 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 <...
alfC's user avatar
  • 16.7k
12 votes
1 answer
295 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 ...
mindentropy's user avatar
0 votes
1 answer
80 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 ...
MBlrd's user avatar
  • 165
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; ...
RedRam's user avatar
  • 537
0 votes
2 answers
86 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 ...
Kyle Gorbski's user avatar

15 30 50 per page
1
2 3 4 5
1156