lemon/bits/utility.h
author deba
Tue, 21 Nov 2006 18:29:31 +0000
changeset 2307 558cc308a4bd
parent 2151 38ec4a930c05
child 2386 81b47fc5c444
permissions -rw-r--r--
Some doc fix
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@2077
    76
deba@1993
    77
  template <typename T>
deba@1993
    78
  struct Wrap {
deba@1993
    79
    const T &value;
deba@1993
    80
    Wrap(const T &t) : value(t) {}
deba@1993
    81
  };
deba@1993
    82
deba@1993
    83
  /**************** dummy class to avoid ambiguity ****************/
deba@1993
    84
deba@1993
    85
  template<int T> struct dummy { dummy(int) {} };
deba@1993
    86
deba@1993
    87
  /**************** enable_if from BOOST ****************/
deba@1993
    88
 
deba@1993
    89
  template <bool B, class T = void>
deba@1993
    90
  struct enable_if_c {
deba@1993
    91
    typedef T type;
deba@1993
    92
  };
deba@1993
    93
deba@1993
    94
  template <class T>
deba@1993
    95
  struct enable_if_c<false, T> {};
deba@1993
    96
deba@1993
    97
  template <class Cond, class T = void> 
deba@1993
    98
  struct enable_if : public enable_if_c<Cond::value, T> {};
deba@1993
    99
deba@1993
   100
  template <bool B, class T>
deba@1993
   101
  struct lazy_enable_if_c {
deba@1993
   102
    typedef typename T::type type;
deba@1993
   103
  };
deba@1993
   104
deba@1993
   105
  template <class T>
deba@1993
   106
  struct lazy_enable_if_c<false, T> {};
deba@1993
   107
deba@1993
   108
  template <class Cond, class T> 
deba@1993
   109
  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
deba@1993
   110
deba@1993
   111
deba@1993
   112
  template <bool B, class T = void>
deba@1993
   113
  struct disable_if_c {
deba@1993
   114
    typedef T type;
deba@1993
   115
  };
deba@1993
   116
deba@1993
   117
  template <class T>
deba@1993
   118
  struct disable_if_c<true, T> {};
deba@1993
   119
deba@1993
   120
  template <class Cond, class T = void> 
deba@1993
   121
  struct disable_if : public disable_if_c<Cond::value, T> {};
deba@1993
   122
deba@1993
   123
  template <bool B, class T>
deba@1993
   124
  struct lazy_disable_if_c {
deba@1993
   125
    typedef typename T::type type;
deba@1993
   126
  };
deba@1993
   127
deba@1993
   128
  template <class T>
deba@1993
   129
  struct lazy_disable_if_c<true, T> {};
deba@1993
   130
deba@1993
   131
  template <class Cond, class T> 
deba@1993
   132
  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
deba@1993
   133
deba@1993
   134
} // namespace lemon
deba@1993
   135
deba@1993
   136
#endif