lemon/bits/enable_if.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 24 Apr 2009 12:22:06 +0200
changeset 613 b1811c363299
parent 314 2cc60866a0c9
permissions -rw-r--r--
Bug fix in NetworkSimplex (#234)
deba@220
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@220
     2
 *
deba@220
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@220
     4
 *
alpar@440
     5
 * Copyright (C) 2003-2009
deba@220
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@220
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@220
     8
 *
deba@220
     9
 * Permission to use, modify and distribute this software is granted
deba@220
    10
 * provided that this copyright notice appears in all copies. For
deba@220
    11
 * precise terms see the accompanying LICENSE file.
deba@220
    12
 *
deba@220
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@220
    14
 * express or implied, and with no claim as to its suitability for any
deba@220
    15
 * purpose.
deba@220
    16
 *
deba@220
    17
 */
deba@220
    18
deba@220
    19
// This file contains a modified version of the enable_if library from BOOST.
deba@220
    20
// See the appropriate copyright notice below.
deba@220
    21
deba@220
    22
// Boost enable_if library
deba@220
    23
deba@220
    24
// Copyright 2003 (c) The Trustees of Indiana University.
deba@220
    25
deba@220
    26
// Use, modification, and distribution is subject to the Boost Software
deba@220
    27
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
deba@220
    28
// http://www.boost.org/LICENSE_1_0.txt)
deba@220
    29
deba@220
    30
//    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
deba@220
    31
//             Jeremiah Willcock (jewillco at osl.iu.edu)
deba@220
    32
//             Andrew Lumsdaine (lums at osl.iu.edu)
deba@220
    33
deba@220
    34
deba@220
    35
#ifndef LEMON_BITS_ENABLE_IF_H
deba@220
    36
#define LEMON_BITS_ENABLE_IF_H
deba@220
    37
kpeter@314
    38
//\file
kpeter@314
    39
//\brief Miscellaneous basic utilities
deba@220
    40
deba@220
    41
namespace lemon
deba@220
    42
{
deba@220
    43
kpeter@314
    44
  // Basic type for defining "tags". A "YES" condition for \c enable_if.
deba@220
    45
kpeter@314
    46
  // Basic type for defining "tags". A "YES" condition for \c enable_if.
kpeter@314
    47
  //
kpeter@314
    48
  //\sa False
deba@220
    49
  struct True {
kpeter@314
    50
    //\e
deba@220
    51
    static const bool value = true;
deba@220
    52
  };
deba@220
    53
kpeter@314
    54
  // Basic type for defining "tags". A "NO" condition for \c enable_if.
deba@220
    55
kpeter@314
    56
  // Basic type for defining "tags". A "NO" condition for \c enable_if.
kpeter@314
    57
  //
kpeter@314
    58
  //\sa True
deba@220
    59
  struct False {
kpeter@314
    60
    //\e
deba@220
    61
    static const bool value = false;
deba@220
    62
  };
deba@220
    63
deba@220
    64
deba@220
    65
deba@220
    66
  template <typename T>
deba@220
    67
  struct Wrap {
deba@220
    68
    const T &value;
deba@220
    69
    Wrap(const T &t) : value(t) {}
deba@220
    70
  };
deba@220
    71
deba@220
    72
  /**************** dummy class to avoid ambiguity ****************/
deba@220
    73
deba@220
    74
  template<int T> struct dummy { dummy(int) {} };
deba@220
    75
deba@220
    76
  /**************** enable_if from BOOST ****************/
deba@220
    77
deba@220
    78
  template <typename Type, typename T = void>
deba@220
    79
  struct exists {
deba@220
    80
    typedef T type;
deba@220
    81
  };
deba@220
    82
deba@220
    83
deba@220
    84
  template <bool B, class T = void>
deba@220
    85
  struct enable_if_c {
deba@220
    86
    typedef T type;
deba@220
    87
  };
deba@220
    88
deba@220
    89
  template <class T>
deba@220
    90
  struct enable_if_c<false, T> {};
deba@220
    91
deba@220
    92
  template <class Cond, class T = void>
deba@220
    93
  struct enable_if : public enable_if_c<Cond::value, T> {};
deba@220
    94
deba@220
    95
  template <bool B, class T>
deba@220
    96
  struct lazy_enable_if_c {
deba@220
    97
    typedef typename T::type type;
deba@220
    98
  };
deba@220
    99
deba@220
   100
  template <class T>
deba@220
   101
  struct lazy_enable_if_c<false, T> {};
deba@220
   102
deba@220
   103
  template <class Cond, class T>
deba@220
   104
  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
deba@220
   105
deba@220
   106
deba@220
   107
  template <bool B, class T = void>
deba@220
   108
  struct disable_if_c {
deba@220
   109
    typedef T type;
deba@220
   110
  };
deba@220
   111
deba@220
   112
  template <class T>
deba@220
   113
  struct disable_if_c<true, T> {};
deba@220
   114
deba@220
   115
  template <class Cond, class T = void>
deba@220
   116
  struct disable_if : public disable_if_c<Cond::value, T> {};
deba@220
   117
deba@220
   118
  template <bool B, class T>
deba@220
   119
  struct lazy_disable_if_c {
deba@220
   120
    typedef typename T::type type;
deba@220
   121
  };
deba@220
   122
deba@220
   123
  template <class T>
deba@220
   124
  struct lazy_disable_if_c<true, T> {};
deba@220
   125
deba@220
   126
  template <class Cond, class T>
deba@220
   127
  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
deba@220
   128
deba@220
   129
} // namespace lemon
deba@220
   130
deba@220
   131
#endif