What is generic Programming ?

Can anybody tell me what is generic programming in simple language, Yesterday I was reading a book, I came to know about this term, I googled it but I did not get it.
I'll give it a try: generic programming is an approach to programming that focuses on algorithm reuse (to contrast, OOP focuses on data reuse).

Generic programming seeks to develop algorithms that accept data of any kind that matches a set of requirements (a "concept" in C++ speak). For example, generic sort (C++'s std::sort) can sort any sequence of elements of any kind -- built-in integers, user-defined integers, strings, vectors of strings, whatever, as long as the sequence is random-accessible and the elements are comparable.

Another important point (and the reason C++ was the first language in which generic programming could be implemented) is that generic algorithms may have multiple implementations for different kinds of data: std::copy can copy any sequence of elements that are copy-constructible, but if those elements happen to be trivially copy-constructible, it will compile to std::memmove instead of compiling to a loop.
Last edited on
Topic archived. No new replies allowed.