Skip to main content

Questions tagged [generics]

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

Filter by
Sorted by
Tagged with
0 votes
0 answers
17 views

Dispatching generic calls and types in TypeScript

I'm not sure if this is an appropriate SE site for this question. I think it belongs here better that to StackOverflow, because it is not about a single particular problem, but if you think otherwise, ...
3 votes
1 answer
48 views

Benchmarking type generic algorithms on type heterogenous problem sets in Rust

I need to benchmark the different code generations of a generic function in rust, for different type parameters. I ran upon this when developing differential equation solvers using ...
2 votes
1 answer
176 views

Using Ada's access type and generics to solve an ODE

This post is linked to Ada: Convert float to decimal I have produced Ada codes which uses the Euler algorithm Euler method to solve an ordinary differential equation. The codes given below are working ...
4 votes
3 answers
176 views

Type Traits for C with _Generic

Motivation: Type traits are useful in defining robust function-like macros. Code below has: IS_COMPATIBLE(EXPR, T) IS_NULLPTR(T)...
6 votes
3 answers
166 views

An Attempt at Creating a Type-Safe, Generic Swap Macro With Compile Time Error Checking

Properties: It evaluates each of A and B only once (sizeof is special, as it doesn't ...
1 vote
0 answers
47 views

Emulating C23's QChar * behavior for basename and strchrnul

To quote @Lundin from What is C23 and why should I care?: Bug fixes for a lot of library functions (search functions in particular): we can now pass a const-qualified pointer parameter to a library ...
9 votes
4 answers
943 views

An Attempt at Creating Generic Min()/Max() for Fundamental Types

The simplest way one can achieve this is to have separate functions for each type with a suffix to differentiate between them like the following: ...
10 votes
3 answers
301 views

Reasonable way to implement "safe" math operations using _Generic?

I've been thinking about a way to make it easier to safely use math operations with C's basic datatypes (e.g. using the CERT C coding standard). So far, I've come up with something like this: ...
1 vote
1 answer
57 views

Generic Min() for Integer Types (including Boolean)

This is a follow-up to Generic Max() for Integer Types (including Boolean) and An Attempt at Creating Generic Min()/Max() for Fundamental Types. What's new: MIN(), ...
8 votes
2 answers
173 views

Generic Max() for Integer Types (including Boolean)

This is a follow-up to An Attempt at Creating Generic min()/max() for Fundamental Types. What's Changed: MIN() has been forsaken for the time being. Mixed types ...
2 votes
0 answers
83 views

Implementing Generic, General, Specific and Portable Bitwise Operations

First my apologies. My mental faculties currently leave rather a lot to be desired and I have thus spend an inordinate amount of time on this pet project of mine, testing myself if you will. I find it ...
0 votes
0 answers
30 views

Lists With Generic Data Types In SwiftUI

I've written a simple list in SwiftUI that accepts a generic data type. The goal was to make a reusable list where when an item was selected, the list would execute a callback with the selected data. ...
-2 votes
1 answer
102 views

C# Implementing a list indexed by generic enums [closed]

I've seen a lot of code bases use Dictionaries with strings as their key. This can be redundant and expensive, so I'm trying to make a class that extends ...
1 vote
1 answer
89 views

Find Method Implementation for Multidimensional Array in C#

I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post. The experimental implementation The ...
2 votes
2 answers
98 views

Generic stack implementation (revision)

The below post is a follow-up of Generic stack implementation. Below follows a header-only implementation of a generic stack (inspired by stb-libraries, following these guidelines: stb-howto.txt). ...
3 votes
1 answer
211 views

Generic stack implementation

The provided code (a header-only library inspired by stb libraries] defines functions for creating a stack, pushing elements onto the stack, popping elements from the stack, peeking at the top element ...
6 votes
2 answers
160 views

Generic map-like function

This function mimics Python's map() function (No, it doesn't support generic return types for the function or multiple iterables) by applying the provided function <...
2 votes
1 answer
2k views

Generic filter model

I'd like to put some of my code under critique. The following code will take a supplier for elements and a filter function. Once provided -> the elements will be held by the model until "refresh" is ...
1 vote
2 answers
147 views

Fully generic, very efficient bidirectional Dijkstra's algorithm in Java

After finding out that my previous implementations are incorrect, I decided to give it another try. I relied on this post. (The entire project resides in this GitHub repository. Contains some unit ...
3 votes
0 answers
76 views

Custom AutoComplete component with Typescript Generics

I've created my own AutoComplete form element based on @nextui-org/autocomplete to be able to use it along with react-hook-form. ...
0 votes
1 answer
2k views

Making a generic web API controller when using multiple tables with similar fields

I have been trying to refactor my code since I found I've been doing a lot of copying and pasting to implement the logic of the web API controllers. Here's how the controllers looked like before ...
4 votes
1 answer
68 views

Ringbuffer over a const generic Array in Rust

I implemented this generic ringbuffer over a const generic array with the usage of the MaybeUninit type. Is there something which is maybe unsound (having the lines ...
36 votes
1 answer
1k views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
3 votes
1 answer
96 views

Sequentially find the indexes of an element into a collection

Util class to find into a collection the indexes of a given element with multiple occurrences from the first index or relative to a given index. ...
2 votes
4 answers
282 views

Generic type data storage

We have a module which can be used by user to store and load value of variables. Every variable has an index associated with it (in the shown code cample this is ommitted and index is instead the data ...
5 votes
2 answers
514 views

Generic matrix library in Java

I have this repository. The most important source files follow. com.github.coderodde.math.linear.matrix.AbstractMatrix.java: ...
5 votes
1 answer
115 views

Instance specific code generation

Disclaimer: I've asked this question before on Stack overflow and got a response that this place would be a better fit so I am copy pasting the question here. I've come up with two different ...
2 votes
1 answer
42 views

Python Module for representation, calculus and rich comparisons between temperature scale instances

ToTemp is a temperature conversion package with Celsius, Delisle, Fahrenheit, Kelvin, Rankine, Réaumur, Newton and Rømer scales. With a documentation and already in PyPI. The source code for the main ...
1 vote
0 answers
225 views

Generic[type[Enum], Protocol[DataFrame]] Dataset with mapped to enum types

Below is my solution for managing multiple DataFrames, in an abstract enough way that it may apply to objects outside of a pandas.DataFrame hence the ...
3 votes
1 answer
805 views

A predicated version of std::for_each

For reasons, I want to implement a predicated version of std::for_each. I know that, in C++20, this is made somewhat redundant or less useful, as we can use ...
5 votes
0 answers
201 views

@lazylist - Converts a Python Generator to a List without evaluating every element

Inspired by a blog I read, I made a LazyList class that can wrap an iterable (list, generator etc.) and turn it into a ...
3 votes
1 answer
341 views

Generic Integer Square Root

I have implemented an integer square root function that is branch-free and runs in constant time, using the first variant found in this answer as a base. All possible values for the types ...
2 votes
1 answer
233 views

Generic Interpolation for many types in C#

I made a generic interpolator for Unity objects, but the way it functions makes me question if there's a better way to approach this problem. I want the logic inside of the ...
2 votes
1 answer
71 views

Small typesafe assertion library, is()

I need to write a function with the following requirements (Programming TypeScript book by B. Cherny, Chapter 4, exercise 5): Implement a small typesafe assertion library, ...
6 votes
2 answers
990 views

Classes representing 2D points and pixels

How can I improve this code or make it tidier? ...
3 votes
1 answer
102 views

rust: idiomatic use of generics when using a filetype-dependent writer

Simplified from https://github.com/132nd-vWing/tacview-splitter. External dependencies: zip crate The code would do the following: read a file from disk (...
7 votes
3 answers
2k views

C++ Generic Callback class with removable listeners by unique id

I'm quite new to the STL. Does this make sense? Is there a better way of removing the listeners instead of using shared_ptr while keeping the code short and simple? Is there something in the STL to ...
1 vote
1 answer
111 views

Correct usage of Java Generics for a simple cache holding objects of any particular type that contain an identifier of any particular type

The Stack Overflow question, I'm trying to create an inMemory database using Collections and generics, presents some code that attempts to use Java Generics for an in-memory cache of objects of any ...
0 votes
1 answer
142 views

Singleton generic implementation of simple LinkedList

I would like to ask if the implementation is ok, and what I can improve. Although I'm not sure if the Singleton is working properly. ...
2 votes
1 answer
666 views

A database trait in Rust. How can I make all these generic parameters easier to use?

I am trying to hide the implementation details of accessing a Postgres database. To do this, I want to create "database" and "transaction" traits for use in a repository struct. ...
1 vote
1 answer
300 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
2 votes
1 answer
996 views

MongoDB abstraction in Go with generics

I'm working on a new project with go. So I figured I would give this new feature a run (it's fun!). Although, I'm not sure I'm implementing this the way it's suposed to be. I've read the following ...
2 votes
1 answer
550 views

JSON save system for Unity

I made a Json save system for my Unity game. I wanted to make something as generic as possible to keep the code DRY. I couldn't find much information online on how to make something generic. Could you ...
2 votes
1 answer
720 views

Generic Pairing Heap Performance

I have made a generic pairing heap library in C. Pairing heaps are one of the several heap variants with better asymptotic running times than standard binary heaps (others include Fibonacci heaps and ...
3 votes
0 answers
104 views

Build the Mountain Car Environment using coupled inheritance and type annotations

This code builds the environment for the standard Mountain Car Problem of reinforcement learning. I'm using Python 3.9 with PyCharm and I'm wishing to use type annotations throughout. I'm trying to ...
1 vote
1 answer
74 views

Stream that computes running median value

I was solving a DSA question, running median in a stream. And I decided to design my own stream class with additional features. ...
6 votes
3 answers
704 views

generic implementation of median

Below is a generic implementation of the summary statistics function Median. Discussion of efficient use of std::nth_element and ...
3 votes
2 answers
700 views

Generic Observer/Listener implementation in Java

I am working on a personal project in university where I am currently trying to make my own implementation of a generic observer pattern that I can use throughout my project. I would appreciate any ...
3 votes
1 answer
1k views

Getting a single result from multiple LiveData objects

I have an Android viewmodel for a Fragment that requires the user to perform multiple tasks. In addition to a LiveData object to track the status of each task, I ...
1 vote
1 answer
51 views

interface different usages issue for two or more different implementations

I am writing a small micro-service in typescript with NestJS. This microservice is responsible of giving a user access to one of our company's systems trial access. At first I used hubspot integration ...

1
2 3 4 5
11