lemon/bits/utility.h
changeset 217 b67149f0e675
parent 117 7b0ce9fb1169
equal deleted inserted replaced
2:c8046f850227 3:feb7da8c822a
     1 /* -*- C++ -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
    81   /**************** dummy class to avoid ambiguity ****************/
    81   /**************** dummy class to avoid ambiguity ****************/
    82 
    82 
    83   template<int T> struct dummy { dummy(int) {} };
    83   template<int T> struct dummy { dummy(int) {} };
    84 
    84 
    85   /**************** enable_if from BOOST ****************/
    85   /**************** enable_if from BOOST ****************/
    86   
    86 
    87   template <typename Type, typename T = void>
    87   template <typename Type, typename T = void>
    88   struct exists {
    88   struct exists {
    89     typedef T type;
    89     typedef T type;
    90   };
    90   };
    91 
    91 
    92  
    92 
    93   template <bool B, class T = void>
    93   template <bool B, class T = void>
    94   struct enable_if_c {
    94   struct enable_if_c {
    95     typedef T type;
    95     typedef T type;
    96   };
    96   };
    97 
    97 
    98   template <class T>
    98   template <class T>
    99   struct enable_if_c<false, T> {};
    99   struct enable_if_c<false, T> {};
   100 
   100 
   101   template <class Cond, class T = void> 
   101   template <class Cond, class T = void>
   102   struct enable_if : public enable_if_c<Cond::value, T> {};
   102   struct enable_if : public enable_if_c<Cond::value, T> {};
   103 
   103 
   104   template <bool B, class T>
   104   template <bool B, class T>
   105   struct lazy_enable_if_c {
   105   struct lazy_enable_if_c {
   106     typedef typename T::type type;
   106     typedef typename T::type type;
   107   };
   107   };
   108 
   108 
   109   template <class T>
   109   template <class T>
   110   struct lazy_enable_if_c<false, T> {};
   110   struct lazy_enable_if_c<false, T> {};
   111 
   111 
   112   template <class Cond, class T> 
   112   template <class Cond, class T>
   113   struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
   113   struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
   114 
   114 
   115 
   115 
   116   template <bool B, class T = void>
   116   template <bool B, class T = void>
   117   struct disable_if_c {
   117   struct disable_if_c {
   119   };
   119   };
   120 
   120 
   121   template <class T>
   121   template <class T>
   122   struct disable_if_c<true, T> {};
   122   struct disable_if_c<true, T> {};
   123 
   123 
   124   template <class Cond, class T = void> 
   124   template <class Cond, class T = void>
   125   struct disable_if : public disable_if_c<Cond::value, T> {};
   125   struct disable_if : public disable_if_c<Cond::value, T> {};
   126 
   126 
   127   template <bool B, class T>
   127   template <bool B, class T>
   128   struct lazy_disable_if_c {
   128   struct lazy_disable_if_c {
   129     typedef typename T::type type;
   129     typedef typename T::type type;
   130   };
   130   };
   131 
   131 
   132   template <class T>
   132   template <class T>
   133   struct lazy_disable_if_c<true, T> {};
   133   struct lazy_disable_if_c<true, T> {};
   134 
   134 
   135   template <class Cond, class T> 
   135   template <class Cond, class T>
   136   struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
   136   struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
   137 
   137 
   138 } // namespace lemon
   138 } // namespace lemon
   139 
   139 
   140 #endif
   140 #endif