Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Template Meta Programming and Number Theory: Part 2

, 24 Aug 2007 CPOL
Using C++ language constructs to introduce abstraction layers
// Functional.h
// Author: Zeeshan Amjad
// 
// Some Basic function for template meta programming
//

#ifndef _FUNCTIONAL_H
#define _FUNCTIONAL_H

// return the value of first parameter
template <int u, int v>
struct Value
{
	enum { value = u };
};

// add two numbers. 
// If second value is missing then return the first value 
template <int u, int v = 0>
struct Add
{
	enum { value = u + v };
};

// subtract one number from another
// If second value is missing then return the first value 
template <int u, int v = 0>
struct Subtract
{
	enum { value = u - v };
};

// subtract one number from another
// If second value is missing then return the first value 
template <int u, int v = 1>
struct Multiply
{
	enum { value = u * v };
};

// divide one number by another
// If second value is missing then return the first value 
template <int u, int v = 1>
struct Divide
{
	enum { value = u / v };
};

// Modulo operator
template <int u, int v>
struct Mod
{
	enum { value = u % v };
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zeeshan Amjad
Software Developer (Senior) Bloomberg LP
United States United States
Working as a Sr C++ Developer at Bloomberg LP

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 24 Aug 2007
Article Copyright 2007 by Zeeshan Amjad
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid