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