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
1 answer

Can I make the Controller endpoint accept different json object (I have the matched class in java side)?

I have different java class in Java side . public class Prov{ private String providerId = ""; private String upin = ""; ... //with getter and setter } public class Proc{ private String procId = ""; private String description = ""; …
0
votes
1 answer

CUDA and C++ with folders structure - generic makefile

I'd like to write generic makefile that compiles and links all my modules. Folders structure: \include ----+Common.h ----+Graph.h ----+GraphColoringCPU.h ----+GraphColoringGPU.cuh ----+LogCreate.h \obj <- initially empty, all .o files ----…
db_k
  • 364
  • 1
  • 5
  • 19
0
votes
1 answer

template definitions syntax

Short question, are these definitions same? 1. template template void function(T1 *a, T2*b); 2. template void function(T1 *a, T2*b);
JamesWebbTelescopeAlien
  • 3,547
  • 2
  • 30
  • 51
0
votes
0 answers

Generic Cuda function - Template & Cuda - c++

My goal is to make a generic Cuda Kernel. My first step is trying to use templates in the function cudaMain (not yet in the Kernel - this will be my second step). cudaMain is called from my c++ main() file. From cudaMain the Kernel is called. This…
aces
  • 185
  • 1
  • 1
  • 10
0
votes
0 answers

How to write a pretty-printer for std::list<*> in C++?

I can easily write a pretty-printer for std::vector<*> like this: template std::ostream &operator<<(std::ostream &origin, const std::vector &vec){ origin << "{ "; for(int i = 0; i < vec.size(); i++) origin << vec[i]…
TorosFanny
  • 1,702
  • 1
  • 16
  • 25
0
votes
2 answers

Why i am getting Segfault in below program for pointer but not for array?

1. int a=3,*p=&a; p++; *p=10; Then it is giving segmentation fault. 2. int a[3]={1,2,3}; a[10]=10; Then it is working properly
Chirag Gangdev
  • 137
  • 2
  • 2
  • 6
0
votes
0 answers

Change iOS components value dynamically (Generic Programming)

To make a generic code, i need to dispatch a value to a component, whatever the type of the component (UISlider,UITextField,UIWebView etc ...) Problem : Sometimes,UIControl manage an Object type (NSString * for UITextField), and sometimes a…
QLag
  • 823
  • 1
  • 13
  • 33
0
votes
1 answer

custom iterator for a collection interface

I have an interface ICollection implementing a collection ArdalanCollection like this: template class ICollection { public: virtual void add(T*) = 0; virtual T* get(int) = 0; virtual int count() = 0; }; template
Alexander1991
  • 217
  • 5
  • 13
0
votes
1 answer

C++ - Templates and Data Types

I am very new to C++ and am trying to create a "Generic Class" that can take any input. I need a way to store whatever input my class receives in either an Array or a Vector. I am however struggling to figure out how to do that. I tried to do this…
Richard
  • 457
  • 1
  • 6
  • 21
0
votes
1 answer

How do I return a generic type while having another generic type as parameter, both required to implement an interace?

Okay yes, the title is kind of confusing. But this is what I want to accomplish: I want to return a list containing elements of a type C. And I want the method to receive a variable of type R. And C have to be a class implementing an interface, i.e.…
0
votes
0 answers

A name for "binary-style" true/false toggle values

I have a table with my user's information, including their address, city, country, phone number, website, social network links, etc... And they have the option to select which of those information they want displayed on their public page. So…
0
votes
1 answer

Is there a better way of obtaining an object's field getters other than java reflection api or i am misusing PropertyDescriptor's getReadMethod?

Context: I am building an Excel document in a generic way with data i receive from a SOAP service endpoint. I receive the data as a List and i have the model (JavaBeans) for every Object i receive according to the method called. So I set the first…
Laurentiu L.
  • 6,566
  • 1
  • 34
  • 60
0
votes
1 answer

How to print LinkedList Node object in reverse order

In the following method reverse() ,I wanted to access the elements of Node and add them in an ArrayList.After that ,using loop, it will print in reverse order. public void reverse(){ Node e = head; ArrayList s = new…
0
votes
1 answer

How to initialize different classes of objects automatically?

I want to make a class registry class that automatically makes a UITableViewCell and when the user presses the button it'll go to that class and run the code. Currently to do something like that, in the view controller I have to do something like…
0
votes
1 answer

One method that can work with both primitive data types and generics?

I recently learnt about generics and re-wrote my old Binary Sorting program which used to only sort values of type int My new implementation will sort everything except primitive data types. Below is the implementation: import…
Siddharth Thevaril
  • 3,722
  • 3
  • 35
  • 71