// -*- C++ -*- // Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. // Permission to use, copy, modify, sell, and distribute this software // is hereby granted without fee, provided that the above copyright // notice appears in all copies, and that both that copyright notice and // this permission notice appear in supporting documentation. None of // the above authors, nor IBM Haifa Research Laboratories, make any // representation about the suitability of this software for any // purpose. It is provided "as is" without express or implied warranty. /** * @file typelist.h * Contains typelist_chain definitions. * Typelists are an idea by Andrei Alexandrescu. */ #ifndef _TYPELIST_H #define _TYPELIST_H 1 #include _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) /** @namespace __gnu_cxx::typelist * @brief GNU typelist extensions for public compile-time use. */ namespace typelist { struct null_type { }; template struct node { typedef Root root; }; // Forward declarations of functors. template struct chain { typedef Hd head; typedef Typelist tail; }; // Apply all typelist types to unary functor. template void apply(Fn&, Typelist); /// Apply all typelist types to generator functor. template void apply_generator(Gn&, Typelist); // Apply all typelist types and values to generator functor. template void apply_generator(Gn&, TypelistT, TypelistV); template struct append; template struct append_typelist; template struct contains; template class Pred> struct filter; template struct at_index; template class Transform> struct transform; template struct flatten; template struct from_first; template struct create1; template struct create2; template struct create3; template struct create4; template struct create5; template struct create6; } // namespace typelist _GLIBCXX_END_NAMESPACE _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) namespace typelist { namespace detail { template struct apply_; template struct apply_ > { void operator()(Fn& f) { f.operator()(Hd()); apply_ next; next(f); } }; template struct apply_ { void operator()(Fn&) { } }; template struct apply_generator1_; template struct apply_generator1_ > { void operator()(Gn& g) { g.template operator()(); apply_generator1_ next; next(g); } }; template struct apply_generator1_ { void operator()(Gn&) { } }; template struct apply_generator2_; template struct apply_generator2_, chain > { void operator()(Gn& g) { g.template operator()(); apply_generator2_ next; next(g); } }; template struct apply_generator2_ { void operator()(Gn&) { } }; template struct append_; template struct append_, Typelist_Chain> { private: typedef append_ append_type; public: typedef chain type; }; template struct append_ { typedef Typelist_Chain type; }; template struct append_ { typedef Typelist_Chain type; }; template<> struct append_ { typedef null_type type; }; template struct append_typelist_; template struct append_typelist_ > { typedef chain type; }; template struct append_typelist_ > { private: typedef typename append_typelist_::type rest_type; public: typedef typename append >::type::root type; }; template struct contains_; template struct contains_ { enum { value = false }; }; template struct contains_, T> { enum { value = contains_::value }; }; template struct contains_, T> { enum { value = true }; }; template class Pred> struct chain_filter_; template class Pred> struct chain_filter_ { typedef null_type type; }; template class Pred> struct chain_filter_, Pred> { private: enum { include_hd = Pred::value }; typedef typename chain_filter_::type rest_type; typedef chain chain_type; public: typedef typename __conditional_type::__type type; }; template struct chain_at_index_; template struct chain_at_index_, 0> { typedef Hd type; }; template struct chain_at_index_, i> { typedef typename chain_at_index_::type type; }; template class Transform> struct chain_transform_; template class Transform> struct chain_transform_ { typedef null_type type; }; template class Transform> struct chain_transform_, Transform> { private: typedef typename chain_transform_::type rest_type; typedef typename Transform::type transform_type; public: typedef chain type; }; template struct chain_flatten_; template struct chain_flatten_ > { typedef typename Hd_Tl::root type; }; template struct chain_flatten_ > { private: typedef typename chain_flatten_::type rest_type; typedef append > append_type; public: typedef typename append_type::type::root type; }; } // namespace detail } // namespace typelist _GLIBCXX_END_NAMESPACE #define _GLIBCXX_TYPELIST_CHAIN1(X0) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN2(X0, X1) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN3(X0, X1, X2) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN4(X0, X1, X2, X3) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) __gnu_cxx::typelist::chain #define _GLIBCXX_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) __gnu_cxx::typelist::chain _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) namespace typelist { template void apply(Fn& fn, Typelist) { detail::apply_ a; a(fn); } template void apply_generator(Fn& fn, Typelist) { detail::apply_generator1_ a; a(fn); } template void apply_generator(Fn& fn, TypelistT, TypelistV) { typedef typename TypelistT::root rootT; typedef typename TypelistV::root rootV; detail::apply_generator2_ a; a(fn); } template struct append { private: typedef typename Typelist0::root root0_type; typedef typename Typelist1::root root1_type; typedef detail::append_ append_type; public: typedef node type; }; template struct append_typelist { private: typedef typename Typelist_Typelist::root root_type; typedef detail::append_typelist_ append_type; public: typedef node type; }; template struct contains { private: typedef typename Typelist::root root_type; public: enum { value = detail::contains_::value }; }; template class Pred> struct filter { private: typedef typename Typelist::root root_type; typedef detail::chain_filter_ filter_type; public: typedef node type; }; template struct at_index { private: typedef typename Typelist::root root_type; typedef detail::chain_at_index_ index_type; public: typedef typename index_type::type type; }; template class Transform> struct transform { private: typedef typename Typelist::root root_type; typedef detail::chain_transform_ transform_type; public: typedef node type; }; template struct flatten { private: typedef typename Typelist_Typelist::root root_type; typedef typename detail::chain_flatten_::type flatten_type; public: typedef node type; }; template struct from_first { private: typedef typename at_index::type first_type; public: typedef node > type; }; template struct create1 { typedef node<_GLIBCXX_TYPELIST_CHAIN1(T1)> type; }; template struct create2 { typedef node<_GLIBCXX_TYPELIST_CHAIN2(T1,T2)> type; }; template struct create3 { typedef node<_GLIBCXX_TYPELIST_CHAIN3(T1,T2,T3)> type; }; template struct create4 { typedef node<_GLIBCXX_TYPELIST_CHAIN4(T1,T2,T3,T4)> type; }; template struct create5 { typedef node<_GLIBCXX_TYPELIST_CHAIN5(T1,T2,T3,T4,T5)> type; }; template struct create6 { typedef node<_GLIBCXX_TYPELIST_CHAIN6(T1,T2,T3,T4,T5,T6)> type; }; } // namespace typelist _GLIBCXX_END_NAMESPACE #endif