|
// 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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.