lemon/utility.h
author alpar
Mon, 06 Feb 2006 09:10:43 +0000
changeset 1959 264811b995f3
parent 1875 98698b69a902
child 1989 d276e88aa48a
permissions -rw-r--r--
Spellcheck
klao@977
     1
/* -*- C++ -*-
klao@977
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, 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
 */
klao@977
    18
alpar@1956
    19
// This file contains a modified version of the enable_if library from BOOST.
alpar@1956
    20
// See the appropriate copyright notice below.
alpar@1956
    21
klao@977
    22
// Boost enable_if library
klao@977
    23
klao@977
    24
// Copyright 2003 © The Trustees of Indiana University.
klao@977
    25
klao@977
    26
// Use, modification, and distribution is subject to the Boost Software
klao@977
    27
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
klao@977
    28
// http://www.boost.org/LICENSE_1_0.txt)
klao@977
    29
klao@977
    30
//    Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
klao@977
    31
//             Jeremiah Willcock (jewillco at osl.iu.edu)
klao@977
    32
//             Andrew Lumsdaine (lums at osl.iu.edu)
klao@977
    33
klao@977
    34
klao@977
    35
#ifndef LEMON_UTILITY_H
klao@977
    36
#define LEMON_UTILITY_H
klao@977
    37
alpar@1447
    38
///\file
alpar@1447
    39
///\brief Miscellaneous basic utilities
alpar@1447
    40
///
alpar@1447
    41
///\todo Please rethink the organisation of the basic files like this.
alpar@1447
    42
///E.g. this file might be merged with invalid.h.
alpar@1447
    43
alpar@1447
    44
klao@977
    45
namespace lemon
klao@977
    46
{
klao@977
    47
alpar@1630
    48
  /// Basic type for defining "tags". A "YES" condition for \c enable_if.
klao@977
    49
alpar@1630
    50
  /// Basic type for defining "tags". A "YES" condition for \c enable_if.
alpar@1630
    51
  ///
alpar@1630
    52
  ///\sa False
alpar@1630
    53
  ///
klao@977
    54
  /// \todo This should go to a separate "basic_types.h" (or something)
klao@977
    55
  /// file.
klao@977
    56
  struct True {
alpar@1630
    57
    ///\e
klao@977
    58
    static const bool value = true;
klao@977
    59
  };
klao@977
    60
alpar@1630
    61
  /// Basic type for defining "tags". A "NO" condition for \c enable_if.
alpar@1630
    62
alpar@1630
    63
  /// Basic type for defining "tags". A "NO" condition for \c enable_if.
alpar@1630
    64
  ///
alpar@1630
    65
  ///\sa True
klao@977
    66
  struct False {
alpar@1630
    67
    ///\e
klao@977
    68
    static const bool value = false;
klao@977
    69
  };
klao@977
    70
deba@1696
    71
  template <bool left, bool right>
deba@1696
    72
  struct _CompileTimeAnd {
deba@1696
    73
    static const bool value = false;
deba@1696
    74
  };
deba@1696
    75
  
deba@1696
    76
  template <>
deba@1696
    77
  struct _CompileTimeAnd<true, true> {
deba@1696
    78
    static const bool value = true;
deba@1696
    79
  };
deba@1696
    80
deba@1696
    81
  template <typename Left, typename Right>
deba@1696
    82
  struct CompileTimeAnd {
deba@1696
    83
    static const bool value = 
deba@1696
    84
    _CompileTimeAnd<Left::value, Right::value>::value;
deba@1696
    85
  };
deba@1696
    86
klao@977
    87
  template <typename T>
klao@977
    88
  struct Wrap {
klao@977
    89
    const T &value;
klao@977
    90
    Wrap(const T &t) : value(t) {}
klao@977
    91
  };
klao@977
    92
alpar@1256
    93
  /**************** dummy class to avoid ambiguity ****************/
klao@977
    94
alpar@1256
    95
  template<int T> struct dummy { dummy(int) {} };
klao@977
    96
klao@977
    97
  /**************** enable_if from BOOST ****************/
klao@977
    98
 
klao@977
    99
  template <bool B, class T = void>
klao@977
   100
  struct enable_if_c {
klao@977
   101
    typedef T type;
klao@977
   102
  };
klao@977
   103
klao@977
   104
  template <class T>
klao@977
   105
  struct enable_if_c<false, T> {};
klao@977
   106
klao@977
   107
  template <class Cond, class T = void> 
klao@977
   108
  struct enable_if : public enable_if_c<Cond::value, T> {};
klao@977
   109
klao@977
   110
  template <bool B, class T>
klao@977
   111
  struct lazy_enable_if_c {
klao@977
   112
    typedef typename T::type type;
klao@977
   113
  };
klao@977
   114
klao@977
   115
  template <class T>
klao@977
   116
  struct lazy_enable_if_c<false, T> {};
klao@977
   117
klao@977
   118
  template <class Cond, class T> 
klao@977
   119
  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
klao@977
   120
klao@977
   121
klao@977
   122
  template <bool B, class T = void>
klao@977
   123
  struct disable_if_c {
klao@977
   124
    typedef T type;
klao@977
   125
  };
klao@977
   126
klao@977
   127
  template <class T>
klao@977
   128
  struct disable_if_c<true, T> {};
klao@977
   129
klao@977
   130
  template <class Cond, class T = void> 
klao@977
   131
  struct disable_if : public disable_if_c<Cond::value, T> {};
klao@977
   132
klao@977
   133
  template <bool B, class T>
klao@977
   134
  struct lazy_disable_if_c {
klao@977
   135
    typedef typename T::type type;
klao@977
   136
  };
klao@977
   137
klao@977
   138
  template <class T>
klao@977
   139
  struct lazy_disable_if_c<true, T> {};
klao@977
   140
klao@977
   141
  template <class Cond, class T> 
klao@977
   142
  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
klao@977
   143
klao@977
   144
} // namespace lemon
klao@977
   145
klao@977
   146
#endif