bin_pow.hh

00001 // This file is a part of Aurelia.
00002 // Copyright (C) 2010  Valentin David
00003 // Copyright (C) 2010  University of Bergen
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #ifndef __BIN_POW_HH
00019 # define __BIN_POW_HH
00020 
00021 # include <type_traits>
00022 
00023 namespace fast {
00024 
00025   template  <typename integral_type, typename N>
00026   struct bin_pow_wrapped: public
00027   std::integral_constant<integral_type,
00028                          bin_pow_wrapped<integral_type,
00029                                          std::integral_constant<integral_type,
00030                                                                 N::value-1>
00031                                          >::value*2> {};
00032 
00033   template <typename integral_type>
00034   struct bin_pow_wrapped<integral_type,
00035                          std::integral_constant<integral_type, 0> >
00036     : public std::integral_constant<integral_type, 1> {};
00037 
00038   template <typename integral_type, integral_type N>
00039   struct bin_pow:
00040     public bin_pow_wrapped<integral_type,
00041                            std::integral_constant<integral_type, N> > {};
00042 
00043   template <typename integral_type, integral_type N>
00044   struct bin_pow_pow {
00045     enum: integral_type {
00046       value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>
00047       ::value
00048     };
00049   };
00050 }
00051 
00052 #endif