A concept is a set of type requirements. For example, you might have a concept called "RandomAccessible" that puts a requirement in a type that it implements operator[](int) O (1) times.
As concepts have been excluded from the upcoming C ++ standard, they exist only as inconspicuously in C ++ as documentation. As an example, you can read the SGI description of the container concept .
When a type meets all the requirements of a concept, you call it a model of that concept. For example, std::vector is a model of the concept of a container (or, equivalently, std::vector of the “Container” models).
Finally, politics is a unit of behavior that can be combined with other units of behavior to create complex classes. For example, suppose you want to create two classes: a fixed-size array and a dynamically resizable array. Both of these classes have many common functions, but they simply differ in storage mechanisms and some functions (for example, you cannot call push_back in a fixed-size array).
template <class T, class StoragePolicy> class array : public StoragePolicy { public: T& operator[](int i) { return data[i]; } }; template <class T, int N> class fixed_storage { T data[N]; }; template <class T> class dynamic_storage { T* data; public: void push_back(const T& value) {
Usage will be as follows:
int main() { array<int, fixed_storage<int, 10> > fixed_array; array<int, dynamic_storage<int> > dynamic_array; dynamic_array.push_back(1); fixed_array[9] = dynamic_array[0]; }
Obviously, this is a very crude and incomplete example, but I hope that it illuminates the concept of politics.
Note that in this example we can say that fixed_storage and dynamic_storage are “models” of the StoragePolicy concept. Of course, we would need to formally determine what exactly StoragePolicy concepts StoragePolicy from their models. In this case, just define the index variable data .