ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_META_ALGORITHM_HPP 00002 #define VIENNAGRID_META_ALGORITHM_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 #include "viennagrid/meta/typelist.hpp" 00017 00023 namespace viennagrid 00024 { 00025 namespace detail 00026 { 00027 template<typename typelist> 00028 struct for_each_impl {}; 00029 00030 template<typename head, typename tail> 00031 struct for_each_impl< viennagrid::typelist<head, tail> > 00032 { 00033 template<typename functor> 00034 static void exec( functor & f) 00035 { 00036 f( tag<head>() ); 00037 for_each_impl<tail>::exec(f); 00038 } 00039 00040 template<typename functor> 00041 static void exec( const functor & f) 00042 { 00043 f( tag<head>() ); 00044 for_each_impl<tail>::exec(f); 00045 } 00046 }; 00047 00048 template<> 00049 struct for_each_impl< viennagrid::null_type > 00050 { 00051 template<typename functor> static void exec( functor & ) {} 00052 template<typename functor> static void exec( const functor & ) {} 00053 }; 00054 00055 00056 template<typename typelist, typename functor> 00057 void for_each(functor & f) 00058 { for_each_impl<typelist>::exec(f); } 00059 00060 template<typename typelist, typename functor> 00061 void for_each(const functor & f) 00062 { for_each_impl<typelist>::exec(f); } 00063 00064 00065 00066 00067 template<template<typename> class functor, typename typelist> 00068 struct TRANSFORM; 00069 00070 00071 template<template<typename> class functor> 00072 struct TRANSFORM<functor, viennagrid::null_type> 00073 { 00074 typedef viennagrid::null_type type; 00075 }; 00076 00077 template<template<typename> class functor, typename head, typename tail> 00078 struct TRANSFORM< functor, viennagrid::typelist<head, tail> > 00079 { 00080 typedef viennagrid::typelist< 00081 typename functor<head>::type, 00082 typename TRANSFORM<functor, tail>::type 00083 > type; 00084 }; 00085 00086 } 00087 } 00088 00089 #endif