Questions tagged [generic-programming]

A style of programming in which algorithms are implemented abstracting from concrete data types. Usually referred to strongly typed languages this term is usually treated as creating software which is minimal in terms of data type requirements and can be instantiated for each conforming data type without changing the callee code.

This tag should be used for questions on applying generic programming techniques. Language specific features (, ) related to issues that are not directly connected with generic programming should not be marked with this tag.

Core ideas of generic programming (GP)

  1. Lifting of an algorithm stands for finding minimal requirements for a data type interface which allow to implement the algorithm. Usually this improves reusability by widening of range of conforming data types. This process reduces coupling of the software modules and reduces dependence on secondary aspects, which typically leads to cleaner code.
  2. Specification is a process of constraining data types, typically to facilitate more efficient implementation of an algorithm.
  3. Concept stands for an interface of a data type which is an object of the lifting and specification processes.
  4. Reusable, efficient code generally depends on a balance between lifting and specification.

Widely known implementations

  1. Standard Template Library (STL) which was created by Alexander Stepanov, a GP pioneer.
  2. Generics in Java and
  3. Generics in .NET

Although less known, the first relatively widely used programming language to provide direct support for generic programming was Ada 83.

1288 questions
0
votes
4 answers

Inheritance in generic types

Can anyone help me in using Where for generic types? I was trying to create a function which does ST with a number of type double or int, so I said it should be generic function. But when I try to assign a value to variables of that generic type, I…
Dr TJ
  • 3,241
  • 2
  • 35
  • 51
0
votes
2 answers

Generic type argumented class with generic type argumented Subclass

I have one class with a generic type, like this: public class Test { /* Some Properties and Fields */ } Now I need a public Property SubTest{T} in class Test{T} with datatype Test{T} public class Test { /* Some…
0
votes
1 answer

Huge c++ project makefile by hand

I'm using CODEO (Eclipse + overlay) to build an app for the ELinOS RTOS. Thing is, I lose the ability to auto-generate the Makefile using eclipse CDT and I have a generic Makefile alreayd generated. Instead of typing this huge Makefile (Lots and…
SOKS
  • 190
  • 3
  • 11
0
votes
1 answer

The correct way to set a function generic and overload it with different arguments within a package

Let's assume that I want to define the function rankMatrix from the Matrix package for my own S4 class objects. Doing this in a running R session seems to be straightforward: library(devtools); library(roxygen2);…
R大卫
  • 150
  • 7
0
votes
2 answers

Is it possible to dynamically handle the input of a dynamically created component?

Disclaimer: I'm new to ReactJS, Javascript and more generally to front-end development. Hi everyone, I decided to build a generic component to handle all the forms I'll be using in my project based on a given template. Generation is quite simple: I…
0
votes
0 answers

Passing type information in scala

If I have some class heirarchy defined like this sealed trait A case class B() extends A case class C() extends A // and so on .. and in a different location I want to call some method dynamically passing above classes as type to that function (eg:…
0
votes
1 answer

Generic way of reading CSV of class hierarchy in scala

I know there are various libraries around to read CSV in scala. I have tried the shapeless way , but I am having trouble reading csv in generic way for a hierarchy . For e.g. I need something like this : abstract class A case class…
Harsh Gupta
  • 339
  • 4
  • 20
0
votes
2 answers

Serialize a function in C

I would like to know if it is possible to serialize a (C-written) function in the C programming language. The context is the following: I have a binary search tree of key-value pairs. The keys are standard null-terminated strings, and the values are…
user4713571
0
votes
2 answers

swift generics return first and last element

I'm trying to get used to generics (never used them in objc) and want to write a toy function that takes an object of any type () and returns the first and last element. Hypothetically, I'd only use this on an array or a string - I keep getting an…
karan satia
  • 307
  • 4
  • 16
0
votes
1 answer

(TypeScript) How to capture the type provided by the user inside the generic function?

I am new to TypeScript and this is the function I've written: /** * @function getComponent() * @description finds and returns the requested type of component, null if not found * @return {any} component */ public…
Omar Huseynov
  • 39
  • 1
  • 1
  • 3
0
votes
1 answer

How to declare a typedef that references itself?

I have a Variant type which I want to use in something like a JSON parser. A type in JSON can include objects and arrays. These objects and arrays can contain members of their own type: typedef variant baseType; typedef…
NeomerArcana
  • 1,978
  • 3
  • 23
  • 50
0
votes
1 answer

C++ how to implement with template specilization or other manner?

I am implementing a Boundary Volumn Hierarchy structure, where the tree has a template like this: template class BoundingTree { /* ... */ } The Coordinate can be Vector2d, Vector3f or any other arbitrary coordinate. To use…
stanleyerror
  • 728
  • 1
  • 9
  • 23
0
votes
0 answers

Java Generics with compilation error for extends base object

I have following class which contains map containing generics of list of objects. I need to put a method addElement() and kind of confused about type of object. What should be type of argument on method addElement() ??? public class Tester{ …
gpa
  • 2,411
  • 6
  • 38
  • 68
0
votes
0 answers

Building a typesafe generic client and server from some schema

Say I have the following schema defined: object CalculatorSchema { case class AddRequest(x: Int, y: Int) case class AddReply(sum: Int) case class SubtractRequest(x: Int, y: Int)   case class SubtractReply(diff: Int)   // Some code to pair…
jvliwanag
  • 1,508
  • 1
  • 13
  • 29
0
votes
1 answer

How to inheritance superClass when the superclass is a generic class in Swift

I have two questions need to be solved . the first Question : A Superclass , the name is FatherClass , a subclass inheritance the super class , please read this code : class FatherClass { } class SubClass : FatherClass { // Error : Reference…
user5465320
  • 719
  • 2
  • 7
  • 15