select.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_SR_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_SR_HH 1
00022 
00023 #include <paludis/util/attributes.hh>
00024 
00025 /** \file
00026  * Declarations for various metaprogramming utility classes.
00027  *
00028  * \ingroup g_oo
00029  *
00030  * \section Examples
00031  *
00032  * - None at this time.
00033  */
00034 
00035 namespace paludis
00036 {
00037     template <bool value_, typename IfTrue_, typename IfFalse_>
00038     struct Select;
00039 
00040     /**
00041      * Metaprogramming: select a type based upon a condition.
00042      *
00043      * \ingroup g_oo
00044      */
00045     template <typename IfTrue_, typename IfFalse_>
00046     struct Select<true, IfTrue_, IfFalse_>
00047     {
00048         /// Our value.
00049         typedef IfTrue_ Type;
00050     };
00051 
00052     /**
00053      * Metaprogramming: select a type based upon a condition.
00054      *
00055      * \ingroup g_oo
00056      */
00057     template <typename IfTrue_, typename IfFalse_>
00058     struct Select<false, IfTrue_, IfFalse_>
00059     {
00060         /// Our value.
00061         typedef IfFalse_ Type;
00062     };
00063 
00064     template <bool value_>
00065     struct SelectValue;
00066 
00067     /**
00068      * Metaprogramming: select a value based upon a condition.
00069      *
00070      * \ingroup g_oo
00071      */
00072     template <>
00073     struct SelectValue<true>
00074     {
00075         template <typename IfTrue_, typename IfFalse_>
00076         static const IfTrue_ & get(const IfTrue_ & v, const IfFalse_ &)
00077         {
00078             return v;
00079         }
00080     };
00081 
00082     /**
00083      * Metaprogramming: select a value based upon a condition.
00084      *
00085      * \ingroup g_oo
00086      */
00087     template <>
00088     struct SelectValue<false>
00089     {
00090         template <typename IfTrue_, typename IfFalse_>
00091         static const IfFalse_ & get(const IfTrue_ &, const IfFalse_ & v)
00092         {
00093             return v;
00094         }
00095     };
00096 }
00097 
00098 #endif
00099 

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4