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

Container for pointers to member functions with different arguments

I am looking everywhere (Modern C++ design & co) but I can't find a nice way to store a set of callbacks that accept different arguments and operate on different classes. I need this because I would like every object of my application to have the…
0
votes
1 answer

generic class for quickDialog forms

Let me first start with explaining the situation. I am making a IOS app that is working with a webservice and a webApplication. Take the following example. Let's say we have company X. company X can make all kinds of forms with the webapplication…
Steaphann
  • 2,797
  • 6
  • 50
  • 109
0
votes
1 answer

Cross-platform development solutions for (mobile) performance computing

I am looking for a programming language/platform which is suited for handling around 1 to 2 GB of data, and can run signal processing algorithms fast enough across platforms (including modern mobile platforms). Did someone come across suitable…
0
votes
3 answers

Java - a single generic method to reverse ArrayList or List of objects

I have seen that there is a very convenient way to reverse ArrayList like here using Collections.reverse() method, but I need to achieve such a reverse operation for several types of primitive objects, like at least ArrayList and List of my custom…
hornetbzz
  • 9,188
  • 5
  • 36
  • 53
0
votes
1 answer

C++: create Pointertype from runtime dimension information

I want to do something like this: template struct GeneratePointerType { typedef typename GeneratePointerType::type* type; static const unsigned int dimensions =…
Kaiserludi
  • 2,434
  • 2
  • 23
  • 41
0
votes
1 answer

use generics to check an @Entity for @Unique

Is it even possible to use generics with genericPersist and isUniqueEntity? The persist method seems fairly straightforward: package net.bounceme.dur.usenet.driver; import java.util.ArrayList; import java.util.List; import…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
1 answer

Why is this generic Interface definition wrong?

I am trying to write an interface that looks something like this public interface IPropertyGroupCollection { IEnumerable _Propertygroups { get;} } public interface IPropertyGroup { IEnumerable> _conditions…
SudheerKovalam
  • 628
  • 2
  • 7
  • 13
0
votes
2 answers

Specializing code basing on type_info object

I've got a type_info object that defines type of property in my property map. I would like to run some piece of code (e.g. reading value from cin) parametrized with the type that is defined by my type_info object. It could be some template function,…
peper0
  • 3,111
  • 23
  • 35
0
votes
2 answers

C++:Use user-defined generic functions

I am now reading 《C++ Standard Library》.And I find something confused in chapter 5.7. As we know,we can write our own functions and algorithms to process elements of collections.Of course these operations may also be generic. Let's see a example.The…
XiaJun
  • 1,855
  • 4
  • 24
  • 41
-1
votes
1 answer

DbContext and DbSet issues in Generic repository

I'm trying to create a project will play the repository role in all my projects. The Idea: The Idea was inspired from Generic Repository pattern, so I'm trying to create a generic class will be the repository. this class will receive the dbcontext…
XDev
  • 125
  • 1
  • 8
-1
votes
1 answer

c# Cast generic List of enum

I have a list of enums that i filled, and for many reason i casted it to an object ob. A function receive this object and try to parse it as a generic Enum. List mList = new List(); // i fill my list …
Samael
  • 61
  • 1
  • 9
-1
votes
1 answer

Filter IQueryable with generic lambda Expression

I am trying to filter the DateTime? fields of my classes with a generic function. But I got the error "The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly…
-1
votes
1 answer

generic comparator function in c with unknown arguments

I'm trying to write a generic function in c that takes two arguments of unknown type and compares them but apparently I'm de referencing from void* to void which is a stupid thing to do but how can i cast 'a' and 'b' if i don't know what type they…
Serofin
  • 57
  • 1
  • 5
-1
votes
1 answer

Data conversion: Assigning 4 byte data from array into 1 byte array

First of all, let me explain a little bit about the environment. I am using C for the embedded 32-bit microcontroller. doing unit tests via various tools but results are the same. printf is used only for a test with MinGW. I am trying to copy data…
codetest
  • 19
  • 7
-1
votes
1 answer

Pass a function with lamba expression to make a generic function

I am using google's AutoValue to generate some configs, but before generating the configs, I would like to make sure that the entries are sanitized and default values are added to the list. The AutoValue part looks like: @AutoValue.Builder …