lemon/bits/utility.h
author deba
Tue, 30 Oct 2007 10:51:07 +0000
changeset 2504 46a82ce84cc6
parent 2391 14a343be7a5a
child 2553 bfced05fa852
permissions -rw-r--r--
Bug 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
 *
alpar@2391
     5
 * Copyright (C) 2003-2007
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@2386
    72
  struct InvalidType {
deba@1993
    73
  };
deba@2077
    74
deba@1993
    75
  template <typename T>
deba@1993
    76
  struct Wrap {
deba@1993
    77
    const T &value;
deba@1993
    78
    Wrap(const T &t) : value(t) {}
deba@1993
    79
  };
deba@1993
    80
deba@1993
    81
  /**************** dummy class to avoid ambiguity ****************/
deba@1993
    82
deba@1993
    83
  template<int T> struct dummy { dummy(int) {} };
deba@1993
    84
deba@1993
    85
  /**************** enable_if from BOOST ****************/
deba@2425
    86
  
deba@2425
    87
  template <typename Type, typename T = void>
deba@2425
    88
  struct exists {
deba@2425
    89
    typedef T type;
deba@2425
    90
  };
deba@2425
    91
deba@1993
    92
 
deba@1993
    93
  template <bool B, class T = void>
deba@1993
    94
  struct enable_if_c {
deba@1993
    95
    typedef T type;
deba@1993
    96
  };
deba@1993
    97
deba@1993
    98
  template <class T>
deba@1993
    99
  struct enable_if_c<false, T> {};
deba@1993
   100
deba@1993
   101
  template <class Cond, class T = void> 
deba@1993
   102
  struct enable_if : public enable_if_c<Cond::value, T> {};
deba@1993
   103
deba@1993
   104
  template <bool B, class T>
deba@1993
   105
  struct lazy_enable_if_c {
deba@1993
   106
    typedef typename T::type type;
deba@1993
   107
  };
deba@1993
   108
deba@1993
   109
  template <class T>
deba@1993
   110
  struct lazy_enable_if_c<false, T> {};
deba@1993
   111
deba@1993
   112
  template <class Cond, class T> 
deba@1993
   113
  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
deba@1993
   114
deba@1993
   115
deba@1993
   116
  template <bool B, class T = void>
deba@1993
   117
  struct disable_if_c {
deba@1993
   118
    typedef T type;
deba@1993
   119
  };
deba@1993
   120
deba@1993
   121
  template <class T>
deba@1993
   122
  struct disable_if_c<true, T> {};
deba@1993
   123
deba@1993
   124
  template <class Cond, class T = void> 
deba@1993
   125
  struct disable_if : public disable_if_c<Cond::value, T> {};
deba@1993
   126
deba@1993
   127
  template <bool B, class T>
deba@1993
   128
  struct lazy_disable_if_c {
deba@1993
   129
    typedef typename T::type type;
deba@1993
   130
  };
deba@1993
   131
deba@1993
   132
  template <class T>
deba@1993
   133
  struct lazy_disable_if_c<true, T> {};
deba@1993
   134
deba@1993
   135
  template <class Cond, class T> 
deba@1993
   136
  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
deba@1993
   137
deba@1993
   138
} // namespace lemon
deba@1993
   139
deba@1993
   140
#endif