"Neal D. Becker" wrote:
>
> I hope it is permissible to ask a mp question.
>
> I'd like to have a template parameter is an int. If represents an
> arithmetic shift of an integral value. If the parameter is positive
> I'd like to shift left, and if negative shift right.
>
> Is it feasible to implement something like this? Any hints?
#include <iostream>
using namespace std;
template< int I > struct is_positive
{
enum { value = ( I >= 0 ) };
};
template< bool, int I > struct f_impl
{
enum { value = ( I << 1 ) };
};
template< int I > struct f_impl< false, I >
{
enum { value = ( I >> 1 ) };
};
template< int I > struct f
{
enum { value = f_impl< is_positive< I >::value, I >::value };
};
int main()
{
cout << f< 42 >::value << endl;
cout << f< -42 >::value << endl;
}
HTH, Daniel
--
Daniel Frey
aixigo AG - financial training, research and technology
Schlo�-Rahe-Stra�e 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: [EMAIL PROTECTED], web: http://www.aixigo.de
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost