Questions tagged [reference]
A reference is a value that enables a program to indirectly access a particular datum, such as a variable or a record, in the computer's memory or in some other storage device.
45 questions
3
votes
1
answer
174
views
Reassignable reference_wrapper with empty state
I created a simple custom refernce_wrapper class template, which, in contrast to std::reference_wrapper, has some additional ...
3
votes
0
answers
85
views
A safe building block for self-referential structs in Rust, without macros
I recently had this (admittedly slightly crazy idea) on how to design a building block that can be used in safe Rust to build self-referential structs. Unlike gsrs or selfref it works completely ...
-3
votes
1
answer
108
views
Should a typecast to a unsigned long reference be used while calling a function or another unsigned long variable should be created? [closed]
I was working on a code base where I have a function definition like this:
...
1
vote
1
answer
59
views
Moveable Points - Update variable without Re-referencing variable? Event Subscriptions? (C#, Unity)
So I have this helper script that I use to move points around manually while debugging:
...
2
votes
2
answers
562
views
Slice function for C
I am trying to create a non-generic slice function. I want a 'view' not a copy.
The scan_from arg is so that successive calls ...
0
votes
1
answer
317
views
1
vote
1
answer
872
views
How to collect reference values from hashmap?
I have written a code snippet to use HashMap<String, Vec<&String>> as the main data structure, and finally, I want to return a collected ...
1
vote
1
answer
76
views
Dropping a row in a dataframe
I have made a function to drop a row in a pandas.DataFrame. Since, in general, the input dataframe of a function is just a reference to the dataframe. So any change made in that function to the ...
2
votes
1
answer
373
views
Handling Rc pointers correctly in a parent/children tree
Needs
A container holds two collections: Parent instances and Child instances; their items can be searched by name;
A child can ...
4
votes
1
answer
2k
views
C++ Optional Reference
Here is a good article on an optional reference type in C++. They discuss std::optional<T&>, but as that doesn't compile I have made my own.
One purpose ...
5
votes
0
answers
145
views
Production planner
I have a class that creates an object, PlannedYear, and then passes that object into several other classes to manipulate it. The ultimate goal of the class is to ...
2
votes
0
answers
138
views
Access a variable after several references
I have a team lead that used to write references in a single script then access it in every script. Like for accessing a variable he has to write code in this way ...
4
votes
2
answers
277
views
Music Theory: The Basics - a Ring
I've recently started building an API that allows a consumer to create and manipulate musical entities such as notes, intervals, scales and chords.
The first step is to create a a foundation of base ...
2
votes
0
answers
35
views
Modelling a program with modules, symbols, and dependencies
My scenario is the following: I'm modelling a Program which has many Modules. Each Module has Symbols, some of which pointing at dependencies, which are other Modules. So a Module can be pointed to by ...
4
votes
1
answer
287
views
Passing file identifiers to all subroutines of fortran code
The Fortran program 'MAIN' below calls 3 subroutines.
It opens a file if it is not present, (overwrites if it is already present).
writes something on the file using the file identifier integer and
...
8
votes
1
answer
547
views
Getting ready for Nullable Reference Types
Looking forward for C# Nullable Reference Types in C# 8.0. I do not like to use the preview implementation in a production code though, so just went with these simple helper classes intending them to ...
4
votes
3
answers
830
views
Using an offset variable to keep track of the next item in a Rust array
I am using an offset variable to track the iteration position, and modifying / returning it. Is the below considered bad practice in Rust? I ask this because I don'...
1
vote
1
answer
5k
views
Javascript Stringify Nested Objects with Loop References
I created these functions that will take any object and stringify it, and can then de-stringify it later.
...
2
votes
1
answer
338
views
Simple Python module to test dictionaries
I have some hardware for which I have a driver for which I have a library which can be used to easily configure and probe the device. Now I want to add support for this library to python because the ...
2
votes
2
answers
159
views
Variables, references and pointers - Write the function set (…) so that the following code works correctly
I have following homework exercise from lecture "Variables, references and pointers":
Write the function set (...) so that the following code works
correctly:
...
2
votes
1
answer
141
views
Variables, references and pointers - Write the function zero (...) so that the following code works correctly
I have following homework exercise from lecture "Variables, references and pointers":
Write the function zero (...) so that the following code works
correctly:
int x = 3;
zero(x);
...
8
votes
4
answers
3k
views
Accept either a existing stream or a filename (to be opened) in a constructor
Context:
In a larger project, I am trying to build an utility class to encapsulate the parsing of input data. And I want it to be able to process either an already existing input stream, or a file ...
5
votes
1
answer
2k
views
c++ forward implementation
this is my implementation of std::forward
...
-1
votes
1
answer
6k
views
Pass object by reference when containing a vector [closed]
I have a class that contains (among other things) a large vector. I need to pass an object of this class to a function.
According to best practices, in C++ vectors and arrays should be passed by ...
4
votes
1
answer
334
views
Creating a TSP level with a linked list
I am trying to solve the Travelling Salesman Problem. This function creates the first level in the form of a linked list.
This is what the levels look like:
This is the code that creates it:
...
2
votes
0
answers
580
views
Reference wrapper for functions overloadings and universal references
I have design a little class to allow to overload a function with universal references for a known type, but I'm not sure if that class will work as expected in any contexts.
The indended purpose is ...
5
votes
1
answer
103
views
Fetching files or directories in a given directory
This is a self-teaching implementation to get files for a given directory in order to simplify os.Walk in Go (avoid to pass a func for recursively walking across ...
12
votes
1
answer
1k
views
An optional_ref<T>
I omitted all free operators but the equality comparisons ones because of verbosity. I am glad about any comments and improvements.
Motivation
I know that optional references are equivalent to ...
6
votes
1
answer
329
views
Using get-setf-expansion
In a previous post at Simplifying complex setf expressions, @sds suggested using the get-setf-expansion macro for implementing place modification, as discussed in ...
2
votes
1
answer
396
views
Templated double ended queue (deque) move semantics edge cases C++
My original deque implementation and efficiency question lacked move semantics. After ratchet freak provided an example of how to define them I decided to try adding them to my deque. The unit test + ...
2
votes
1
answer
2k
views
Ensure that ICommand implementation properly uses weak references
I am building an implementation of System.Windows.Input.ICommand that is like the commonly used RelayCommand, but doesn't keep a ...
6
votes
3
answers
1k
views
View programming pattern in C++ without raw pointers
I'm trying to achieve, for lack of a better term, a "view" pattern in C++. It's probably most comparable to "views" in the Database world, where one can make a query, and then perhaps aggregate the ...
1
vote
1
answer
409
views
Binary Search Tree insert while keeping track of parent for node to be added - iteration 2
Follow up question to
Binary Search Tree insert while keeping track of parent for node to be added
I am implementing a red black tree for fun and am wondering how I should modify my basic BST insert....
1
vote
2
answers
732
views
Binary Search Tree insert while keeping track of parent for node to be added
This question has a follow up question:
Binary Search Tree insert while keeping track of parent for node to be added - iteration 2
I am implementing a red black tree for fun and am wondering how I ...
5
votes
1
answer
1k
views
Add values to a multidimensional array of unknown depth
I have the following class:
...
7
votes
2
answers
6k
views
Calculating the price of movie tickets based on multiple inputs
I have modularized my code and currently my "main" function is movieSalesReport(). I am coming from Python where you can have the functions return multiple values. ...
10
votes
3
answers
4k
views
"Suspicious comparison of integer references" while checking for a monotonically increasing sequence
I have the following code which iterates on an Integer[] and makes sure that the the values in the array are in ascending order and that there are no neighbouring ...
2
votes
1
answer
7k
views
StringRef - read only std::string like class similar to boost::string_ref
Idea behind the class is same as boost::string_ref or llvm::SrtingRef.
StringRef is immutable and not-owning.
I did not ...
7
votes
1
answer
186
views
Displaying a video player to eligible users
I posted this on Stack Overflow, but it was suggested that I move it over to Code Review.
I would like some feedback on the way I decided to clean up code from the in a .NET project that had ...
4
votes
1
answer
1k
views
Universal "call" function
I need a function call(f, args...) which calls the "function" f with the arguments args.... ...
2
votes
2
answers
4k
views
Writing a class for common block of code used in many other classes
In this I have written the setAnalyticsInfo() method. The code inside this is common to almost all other (30) classes, so I have created ...
1
vote
2
answers
510
views
Deep reference and object passing
I'm curious if this is the right way of going about the issue:
...
6
votes
2
answers
14k
views
Passing parameters by reference [closed]
Wouldn't it be better to always pass parameters by reference to avoid creating unnecessary copies?
...
4
votes
4
answers
235
views
Reference type and constructors [closed]
Code in Java but should be readable also for c#...
Let's assume I have a class with some reference types. Example:
...
3
votes
2
answers
1k
views
Am I using C++ pointers and references correctly?
I am a newbie to C++ programming and am currently reading this book called Jumping to C++ by Alex Allain. I have finished the pointers chapter and I am doing the exercises at the end of the chapter.
...