lemon/bits/enable_if.h
changeset 221 64613d8fae28
child 314 2cc60866a0c9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/enable_if.h	Tue Jul 15 18:49:30 2008 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library.
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +// This file contains a modified version of the enable_if library from BOOST.
    1.23 +// See the appropriate copyright notice below.
    1.24 +
    1.25 +// Boost enable_if library
    1.26 +
    1.27 +// Copyright 2003 (c) The Trustees of Indiana University.
    1.28 +
    1.29 +// Use, modification, and distribution is subject to the Boost Software
    1.30 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.31 +// http://www.boost.org/LICENSE_1_0.txt)
    1.32 +
    1.33 +//    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
    1.34 +//             Jeremiah Willcock (jewillco at osl.iu.edu)
    1.35 +//             Andrew Lumsdaine (lums at osl.iu.edu)
    1.36 +
    1.37 +
    1.38 +#ifndef LEMON_BITS_ENABLE_IF_H
    1.39 +#define LEMON_BITS_ENABLE_IF_H
    1.40 +
    1.41 +///\file
    1.42 +///\brief Miscellaneous basic utilities
    1.43 +
    1.44 +namespace lemon
    1.45 +{
    1.46 +
    1.47 +  /// Basic type for defining "tags". A "YES" condition for \c enable_if.
    1.48 +
    1.49 +  /// Basic type for defining "tags". A "YES" condition for \c enable_if.
    1.50 +  ///
    1.51 +  ///\sa False
    1.52 +  struct True {
    1.53 +    ///\e
    1.54 +    static const bool value = true;
    1.55 +  };
    1.56 +
    1.57 +  /// Basic type for defining "tags". A "NO" condition for \c enable_if.
    1.58 +
    1.59 +  /// Basic type for defining "tags". A "NO" condition for \c enable_if.
    1.60 +  ///
    1.61 +  ///\sa True
    1.62 +  struct False {
    1.63 +    ///\e
    1.64 +    static const bool value = false;
    1.65 +  };
    1.66 +
    1.67 +
    1.68 +
    1.69 +  template <typename T>
    1.70 +  struct Wrap {
    1.71 +    const T &value;
    1.72 +    Wrap(const T &t) : value(t) {}
    1.73 +  };
    1.74 +
    1.75 +  /**************** dummy class to avoid ambiguity ****************/
    1.76 +
    1.77 +  template<int T> struct dummy { dummy(int) {} };
    1.78 +
    1.79 +  /**************** enable_if from BOOST ****************/
    1.80 +
    1.81 +  template <typename Type, typename T = void>
    1.82 +  struct exists {
    1.83 +    typedef T type;
    1.84 +  };
    1.85 +
    1.86 +
    1.87 +  template <bool B, class T = void>
    1.88 +  struct enable_if_c {
    1.89 +    typedef T type;
    1.90 +  };
    1.91 +
    1.92 +  template <class T>
    1.93 +  struct enable_if_c<false, T> {};
    1.94 +
    1.95 +  template <class Cond, class T = void>
    1.96 +  struct enable_if : public enable_if_c<Cond::value, T> {};
    1.97 +
    1.98 +  template <bool B, class T>
    1.99 +  struct lazy_enable_if_c {
   1.100 +    typedef typename T::type type;
   1.101 +  };
   1.102 +
   1.103 +  template <class T>
   1.104 +  struct lazy_enable_if_c<false, T> {};
   1.105 +
   1.106 +  template <class Cond, class T>
   1.107 +  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
   1.108 +
   1.109 +
   1.110 +  template <bool B, class T = void>
   1.111 +  struct disable_if_c {
   1.112 +    typedef T type;
   1.113 +  };
   1.114 +
   1.115 +  template <class T>
   1.116 +  struct disable_if_c<true, T> {};
   1.117 +
   1.118 +  template <class Cond, class T = void>
   1.119 +  struct disable_if : public disable_if_c<Cond::value, T> {};
   1.120 +
   1.121 +  template <bool B, class T>
   1.122 +  struct lazy_disable_if_c {
   1.123 +    typedef typename T::type type;
   1.124 +  };
   1.125 +
   1.126 +  template <class T>
   1.127 +  struct lazy_disable_if_c<true, T> {};
   1.128 +
   1.129 +  template <class Cond, class T>
   1.130 +  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
   1.131 +
   1.132 +} // namespace lemon
   1.133 +
   1.134 +#endif