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