typelist.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00046 #ifndef TYPELIST_HPP
00047 #define TYPELIST_HPP
00048 
00049 #ifdef _MSC_VER
00050 #pragma warning(disable: 4503)
00051 #endif // #ifdef _MSC_VER
00052 
00053 #include <ext/pb_assoc/detail/type_utils.hpp>
00054 
00055 namespace pb_assoc
00056 {
00057 
00058   namespace detail
00059   {
00060 
00061     struct null_type
00062     { };
00063 
00064     template<typename Hd, typename Tl>
00065     struct typelist_chain
00066     {
00067       typedef Hd head;
00068 
00069       typedef Tl tail;
00070     };
00071 
00072     template<class Root>
00073     struct typelist
00074     {
00075       typedef Root root;
00076     };
00077 
00078 #define PB_ASSOC_TYPELIST_CHAIN1(X0) pb_assoc::detail::typelist_chain<X0, pb_assoc::detail::null_type>
00079 #define PB_ASSOC_TYPELIST_CHAIN2(X0, X1) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN1(X1) >
00080 #define PB_ASSOC_TYPELIST_CHAIN3(X0, X1, X2) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN2(X1, X2) >
00081 #define PB_ASSOC_TYPELIST_CHAIN4(X0, X1, X2, X3) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN3(X1, X2, X3) >
00082 #define PB_ASSOC_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN4(X1, X2, X3, X4) >
00083 #define PB_ASSOC_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN5(X1, X2, X3, X4, X5) >
00084 #define PB_ASSOC_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN6(X1, X2, X3, X4, X5, X6) >
00085 #define PB_ASSOC_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN7(X1, X2, X3, X4, X5, X6, X7) >
00086 #define PB_ASSOC_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN8(X1, X2, X3, X4, X5, X6, X7, X8) >
00087 #define PB_ASSOC_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN9(X1, X2, X3, X4, X5, X6, X7, X8, X9) >
00088 #define PB_ASSOC_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN10(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) >
00089 #define PB_ASSOC_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN11(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) >
00090 #define PB_ASSOC_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN12(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) >
00091 #define PB_ASSOC_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN13(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) >
00092 #define PB_ASSOC_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) pb_assoc::detail::typelist_chain<X0, PB_ASSOC_TYPELIST_CHAIN14(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) >
00093 
00094 #include <ext/pb_assoc/detail/typelist/typelist_apply.hpp>
00095 
00096     template<class Fn, class Typelist>
00097     void
00098     typelist_apply(Fn& r_fn, Typelist /*tl*/)
00099     {
00100       detail::apply_<
00101     Fn,
00102     typename Typelist::root>
00103     a;
00104 
00105       a(r_fn);
00106     }
00107 
00108 #include <ext/pb_assoc/detail/typelist/typelist_append.hpp>
00109 
00110     template<class Typelist0, class Typelist1>
00111     struct typelist_append
00112     {
00113     private:
00114       typedef
00115       typename detail::typelist_append_<
00116     typename Typelist0::root,
00117     typename Typelist1::root>::type
00118       res_hd;
00119 
00120     public:
00121       typedef typelist< res_hd> type;
00122     };
00123 
00124 #include <ext/pb_assoc/detail/typelist/typelist_typelist_append.hpp>
00125 
00126     template<class Typelist_Typelist>
00127     struct typelist_typelist_append
00128     {
00129     private:
00130       typedef
00131       typename detail::typelist_typelist_append_<
00132     typename Typelist_Typelist::root>::type
00133       res_hd;
00134 
00135     public:
00136       typedef typelist< res_hd> type;
00137     };
00138 
00139 #include <ext/pb_assoc/detail/typelist/typelist_contains.hpp>
00140 
00141     template<class Typelist, class T>
00142     struct typelist_contains
00143     {
00144       enum
00145     {
00146       value =
00147       detail::typelist_contains_<
00148       typename Typelist::root,
00149       T>::value
00150     };
00151     };
00152 
00153 #include <ext/pb_assoc/detail/typelist/typelist_filter.hpp>
00154 
00155     template<class Typelist, template<typename T>
00156     class Pred>
00157     struct typelist_filter
00158     {
00159     private:
00160       typedef
00161       typename detail::typelist_chain_filter_<
00162     typename Typelist::root,
00163     Pred>::type
00164       root_type;
00165 
00166     public:
00167       typedef typelist< root_type> type;
00168     };
00169 
00170 #include <ext/pb_assoc/detail/typelist/typelist_at_index.hpp>
00171 
00172     template<class Typelist, int i>
00173     struct typelist_at_index
00174     {
00175       typedef
00176       typename detail::typelist_chain_at_index_<
00177     typename Typelist::root,
00178     i>::type
00179       type;
00180     };
00181 
00182 #include <ext/pb_assoc/detail/typelist/typelist_transform.hpp>
00183 
00184     template<class Typelist, template<class T>
00185     class Transform>
00186     struct typelist_transform
00187     {
00188     private:
00189       typedef
00190       typename detail::typelist_chain_transform_<
00191     typename Typelist::root,
00192     Transform>::type
00193       root_type;
00194 
00195     public:
00196       typedef typelist< root_type> type;
00197     };
00198 
00199 #undef PB_ASSOC_TYPELIST_CHAIN1
00200 #undef PB_ASSOC_TYPELIST_CHAIN2
00201 #undef PB_ASSOC_TYPELIST_CHAIN3
00202 #undef PB_ASSOC_TYPELIST_CHAIN4
00203 #undef PB_ASSOC_TYPELIST_CHAIN5
00204 #undef PB_ASSOC_TYPELIST_CHAIN6
00205 #undef PB_ASSOC_TYPELIST_CHAIN7
00206 #undef PB_ASSOC_TYPELIST_CHAIN8
00207 #undef PB_ASSOC_TYPELIST_CHAIN9
00208 #undef PB_ASSOC_TYPELIST_CHAIN10
00209 #undef PB_ASSOC_TYPELIST_CHAIN11
00210 #undef PB_ASSOC_TYPELIST_CHAIN12
00211 #undef PB_ASSOC_TYPELIST_CHAIN13
00212 #undef PB_ASSOC_TYPELIST_CHAIN14
00213 #undef PB_ASSOC_TYPELIST_CHAIN15
00214 
00215   } // namespace detail
00216 
00217 } // namespace pb_assoc
00218 
00219 #endif // #ifndef TYPELIST_HPP
00220 

Generated on Tue Feb 2 16:56:52 2010 for GNU C++ STL by  doxygen 1.4.7