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

How to build an in-memory state engine at runtime

, 28 Oct 2007 CPOL
A C++ template for an efficient in-memory state engine.
tag_tree.zip
cp
Debug
TagTree.exe
sources
algorithm
container
general
mpl
tag_tree.pdf
//	Copyright � 2007, solosTec
//  All rights reserved.
//---------------------------------------------------------------------
//	License for redistribution is the GNU General Public License v2.
//	See the included readme.txt for details.
//---------------------------------------------------------------------
//	developed by solosTec
//	http://www.solostec.de
//---------------------------------------------------------------------
//
//	$Author: $
//	$Revision: $
/*	$Log: $
*/
//---------------------------------------------------------------------
/**
 *	calculating Base to the power of N.
 *	TODO: make more compatible with the BOOST mpl stuff.
 */
#pragma once
#include <boost/mpl/integral_c.hpp>
#include <boost/mpl/next_prior.hpp>

namespace turban {
namespace mpl {

//	+-----------------------------------------------------------------+
//	| power
//	+-----------------------------------------------------------------+
//
//	Usage: unsigned x = power < unsigned, 2, 8 >::value;
//	x is 256.
template < typename T, T base_, T x_ >
struct power
{ 
	template < T n_ >
	struct calculate
	{
		typedef boost::mpl::integral_c< T, n_ > counter_;
		typedef typename boost::mpl::prior< counter_ >::type prior_;
		typedef boost::mpl::integral_c< T, calculate< prior_::value >::result_::value * base_ > result_;
	};

	template < >
	struct calculate< 0 >
	{
		typedef boost::mpl::integral_c< T, 0 > result_;
	};

	typedef typename calculate< x_ >::result_ result;
	enum { value = result::value };

};
}	//	namespace mpl
}	//	namespace turban

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

osy
Software Developer (Senior)
Germany Germany
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 28 Oct 2007
Article Copyright 2007 by osy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid