utility.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  *
00003  * This file is a part of LEMON, a generic C++ optimization library
00004  *
00005  * Copyright (C) 2003-2006
00006  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00007  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00008  *
00009  * Permission to use, modify and distribute this software is granted
00010  * provided that this copyright notice appears in all copies. For
00011  * precise terms see the accompanying LICENSE file.
00012  *
00013  * This software is provided "AS IS" with no warranty of any kind,
00014  * express or implied, and with no claim as to its suitability for any
00015  * purpose.
00016  *
00017  */
00018 
00019 // This file contains a modified version of the enable_if library from BOOST.
00020 // See the appropriate copyright notice below.
00021 
00022 // Boost enable_if library
00023 
00024 // Copyright 2003 © The Trustees of Indiana University.
00025 
00026 // Use, modification, and distribution is subject to the Boost Software
00027 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00028 // http://www.boost.org/LICENSE_1_0.txt)
00029 
00030 //    Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
00031 //             Jeremiah Willcock (jewillco at osl.iu.edu)
00032 //             Andrew Lumsdaine (lums at osl.iu.edu)
00033 
00034 
00035 #ifndef LEMON_UTILITY_H
00036 #define LEMON_UTILITY_H
00037 
00043 
00044 
00045 namespace lemon
00046 {
00047 
00049 
00056   struct True {
00058     static const bool value = true;
00059   };
00060 
00062 
00066   struct False {
00068     static const bool value = false;
00069   };
00070 
00071   template <bool left, bool right>
00072   struct _CompileTimeAnd {
00073     static const bool value = false;
00074   };
00075   
00076   template <>
00077   struct _CompileTimeAnd<true, true> {
00078     static const bool value = true;
00079   };
00080 
00081   template <typename Left, typename Right>
00082   struct CompileTimeAnd {
00083     static const bool value = 
00084     _CompileTimeAnd<Left::value, Right::value>::value;
00085   };
00086 
00087   template <typename T>
00088   struct Wrap {
00089     const T &value;
00090     Wrap(const T &t) : value(t) {}
00091   };
00092 
00093   /**************** dummy class to avoid ambiguity ****************/
00094 
00095   template<int T> struct dummy { dummy(int) {} };
00096 
00097   /**************** enable_if from BOOST ****************/
00098  
00099   template <bool B, class T = void>
00100   struct enable_if_c {
00101     typedef T type;
00102   };
00103 
00104   template <class T>
00105   struct enable_if_c<false, T> {};
00106 
00107   template <class Cond, class T = void> 
00108   struct enable_if : public enable_if_c<Cond::value, T> {};
00109 
00110   template <bool B, class T>
00111   struct lazy_enable_if_c {
00112     typedef typename T::type type;
00113   };
00114 
00115   template <class T>
00116   struct lazy_enable_if_c<false, T> {};
00117 
00118   template <class Cond, class T> 
00119   struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
00120 
00121 
00122   template <bool B, class T = void>
00123   struct disable_if_c {
00124     typedef T type;
00125   };
00126 
00127   template <class T>
00128   struct disable_if_c<true, T> {};
00129 
00130   template <class Cond, class T = void> 
00131   struct disable_if : public disable_if_c<Cond::value, T> {};
00132 
00133   template <bool B, class T>
00134   struct lazy_disable_if_c {
00135     typedef typename T::type type;
00136   };
00137 
00138   template <class T>
00139   struct lazy_disable_if_c<true, T> {};
00140 
00141   template <class Cond, class T> 
00142   struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
00143 
00144 } // namespace lemon
00145 
00146 #endif

Generated on Fri Feb 3 18:39:51 2006 for LEMON by  doxygen 1.4.6