Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

utility.h

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

Generated on Sat Aug 27 14:14:55 2005 for LEMON by  doxygen 1.4.4