| 
     1 /* -*- C++ -*-  | 
         | 
     2  *  | 
         | 
     3  * src/lemon/utility.h - Part of LEMON, a generic C++ optimization library  | 
         | 
     4  *  | 
         | 
     5  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi  | 
         | 
     6  * Kutatocsoport (Egervary Combinatorial Optimization Research Group,  | 
         | 
     7  * EGRES).  | 
         | 
     8  *  | 
         | 
     9  * Permission to use, modify and distribute this software is granted  | 
         | 
    10  * provided that this copyright notice appears in all copies. For  | 
         | 
    11  * precise terms see the accompanying LICENSE file.  | 
         | 
    12  *  | 
         | 
    13  * This software is provided "AS IS" with no warranty of any kind,  | 
         | 
    14  * express or implied, and with no claim as to its suitability for any  | 
         | 
    15  * purpose.  | 
         | 
    16  *  | 
         | 
    17  * This file contains a modified version of the enable_if library from BOOST.  | 
         | 
    18  * See the appropriate copyright notice below.  | 
         | 
    19  */  | 
         | 
    20   | 
         | 
    21 // Boost enable_if library  | 
         | 
    22   | 
         | 
    23 // Copyright 2003 © The Trustees of Indiana University.  | 
         | 
    24   | 
         | 
    25 // Use, modification, and distribution is subject to the Boost Software  | 
         | 
    26 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at  | 
         | 
    27 // http://www.boost.org/LICENSE_1_0.txt)  | 
         | 
    28   | 
         | 
    29 //    Authors: Jaakko Järvi (jajarvi at osl.iu.edu)  | 
         | 
    30 //             Jeremiah Willcock (jewillco at osl.iu.edu)  | 
         | 
    31 //             Andrew Lumsdaine (lums at osl.iu.edu)  | 
         | 
    32   | 
         | 
    33   | 
         | 
    34 #ifndef LEMON_UTILITY_H  | 
         | 
    35 #define LEMON_UTILITY_H  | 
         | 
    36   | 
         | 
    37 namespace lemon  | 
         | 
    38 { | 
         | 
    39   | 
         | 
    40   /// Basic type for defining "tags". A "YES" condidion for enable_if.  | 
         | 
    41   | 
         | 
    42   /// \todo This should go to a separate "basic_types.h" (or something)  | 
         | 
    43   /// file.  | 
         | 
    44   struct True { | 
         | 
    45     static const bool value = true;  | 
         | 
    46   };  | 
         | 
    47   | 
         | 
    48   /// Basic type for defining "tags". A "NO" condidion for enable_if.  | 
         | 
    49   struct False { | 
         | 
    50     static const bool value = false;  | 
         | 
    51   };  | 
         | 
    52   | 
         | 
    53   template <typename T>  | 
         | 
    54   struct Wrap { | 
         | 
    55     const T &value;  | 
         | 
    56     Wrap(const T &t) : value(t) {} | 
         | 
    57   };  | 
         | 
    58   | 
         | 
    59   | 
         | 
    60   | 
         | 
    61   /**************** enable_if from BOOST ****************/  | 
         | 
    62    | 
         | 
    63   template <bool B, class T = void>  | 
         | 
    64   struct enable_if_c { | 
         | 
    65     typedef T type;  | 
         | 
    66   };  | 
         | 
    67   | 
         | 
    68   template <class T>  | 
         | 
    69   struct enable_if_c<false, T> {}; | 
         | 
    70   | 
         | 
    71   template <class Cond, class T = void>   | 
         | 
    72   struct enable_if : public enable_if_c<Cond::value, T> {}; | 
         | 
    73   | 
         | 
    74   template <bool B, class T>  | 
         | 
    75   struct lazy_enable_if_c { | 
         | 
    76     typedef typename T::type type;  | 
         | 
    77   };  | 
         | 
    78   | 
         | 
    79   template <class T>  | 
         | 
    80   struct lazy_enable_if_c<false, T> {}; | 
         | 
    81   | 
         | 
    82   template <class Cond, class T>   | 
         | 
    83   struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {}; | 
         | 
    84   | 
         | 
    85   | 
         | 
    86   template <bool B, class T = void>  | 
         | 
    87   struct disable_if_c { | 
         | 
    88     typedef T type;  | 
         | 
    89   };  | 
         | 
    90   | 
         | 
    91   template <class T>  | 
         | 
    92   struct disable_if_c<true, T> {}; | 
         | 
    93   | 
         | 
    94   template <class Cond, class T = void>   | 
         | 
    95   struct disable_if : public disable_if_c<Cond::value, T> {}; | 
         | 
    96   | 
         | 
    97   template <bool B, class T>  | 
         | 
    98   struct lazy_disable_if_c { | 
         | 
    99     typedef typename T::type type;  | 
         | 
   100   };  | 
         | 
   101   | 
         | 
   102   template <class T>  | 
         | 
   103   struct lazy_disable_if_c<true, T> {}; | 
         | 
   104   | 
         | 
   105   template <class Cond, class T>   | 
         | 
   106   struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; | 
         | 
   107   | 
         | 
   108 } // namespace lemon  | 
         | 
   109   | 
         | 
   110 #endif  |