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
3 answers

Is it possible to check the type of an argument passed to a function and treat it accordingly in JAVA?

For example, there needs to be a written a generic program for addition. It needs to be intelligent in a way that it determines the type of arguments passed to it and then output the answer in the same type. For more elaboration: If I want to…
0
votes
0 answers

Abstract template class and template childs

I have a problem with creating base class for DoubleLinkedList. Right now it's giving me this error /tmp/cc3lORia.o:(.rodata._ZTV24AbstractDoubleLinkedListIiE[_ZTV24AbstractDoubleLinkedListIiE]+0x10): undefined reference to …
user1685095
  • 5,787
  • 9
  • 51
  • 100
0
votes
1 answer

How could I create a sub type of `I` that would wrap other sub types of `I`?

Given the following in Java: public interface Reply { T data(); } public class StatusReply implements Reply { private final String status; public StatusReply(String status) { this.status = status; } @Override public…
0
votes
2 answers

Linq to Generic list C# Data Filtering issue

I am having a problem with following linq query in my c# code. I want to exclude data that has jobChangeTypeId Unallocate or Delete but its bringing them in the resultset. foreach (EmployeejobAudit empjobAudit in list) { int…
3355307
  • 1,508
  • 4
  • 17
  • 42
0
votes
0 answers

Filter sequence to subsequence with elements evenly apart

I have an input of integers (or floats), eg. 100, 203, 230, 280, 400, 410, 505, 600 And I want to filter them to get a subsequence so that the numbers would be almost evenly apart, that is, remove outsiders, in my case, the filtered sequence would…
Jake B.
  • 435
  • 3
  • 13
0
votes
1 answer

How to avoid repetition of the enclosing class type when auto and decltype() cannot be used

I recently discovered the auto and decltype() features of C++11, which are excellent, as they allow eliminating a lot of redundant type code. However, there are contexts where they cannot be used. One example I'm primarily asking about is if you…
bgoldst
  • 34,190
  • 6
  • 38
  • 64
0
votes
1 answer

Why does C++ standard make regex algorithms free functions?

I'm wondering why C++ standard decided to make regex_* functions (regex_match, regex_search, regex_replace) non-member non-friend. They all need to access basic_regex's internals in order to perform the algorithms. Why don't they make them member…
Cranky
  • 42
  • 1
  • 3
0
votes
1 answer

Adding Handler methods in a generic way to correlate to Handler names specified in an xml

I have ~100 tasks described in Tasks.xml. Each task, has some fields such as name, index and priority. In the program eventually each task is represented by the Class Task. I got a requirement to add the ability to run a handler per each task (there…
0
votes
1 answer

Creating a generic task in Java using a timer

In an Android game, I ask the player a question and I want to give different hints after different lengths of time, and finally give the answer, if the player fails to answer in time. The questions, the hints and the delay times are read in from an…
James Newton
  • 6,623
  • 8
  • 49
  • 113
0
votes
1 answer

How can implement a C++ vector that points to other, multiply typed vectors?

I want to store elements of multiple types in a single vector, while keeping elements of the same type contiguous. The types are derived from a base class and I expect different types to be implemented throughout the development cycle. For this…
0
votes
1 answer

C++ Reactor using base & derived classes containing functional objects of different types

I've created this example reactor program to test functionality I wanted to demonstrate. Essentially the program defines: Two functional objects to be called on different events. A base & derived class; the intention of which is to allow different…
GoFaster
  • 835
  • 1
  • 12
  • 23
0
votes
1 answer

how to invoke PageJpaController.create from a Facade?

What is the correct way to invoke PageFacade, or how can PageFacade be modified, so that it invokes PageJpaController.create()? I'm not quite sure how to use the generic AbstractFacade class for this purpose. While I know that the following…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
0 answers

C# Opposite of "Anonymous" Function

When I try to say: I moved an anonymous method to a ? one where ? is meant to describe just a normal function, with a name, return type, named arguments etc. What would be the correct adjective to use, eg. Concrete, Named, Normal, Class, Member,…
mungflesh
  • 776
  • 11
  • 22
0
votes
3 answers

Genetic Parameters in Constructor

I have the following loop in RunWebTest method which can work with different type of classes passed to it. Now the issue is that I don't know how to modify this code so I could pass different parameters type to the constructor of the class: Public…
Afflatus
  • 933
  • 1
  • 12
  • 39
0
votes
3 answers

C Code: Passing expression as an argument in recursion call

I am practicing some C questions came across a scenario where a recursive function calls itself with an expression as an argument. Pow(double x, unsigned n){ ..... ..... return Pow(x*x,n/2); } My question is whether the arguments are passed…