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