lemon/utility.h
author deba
Wed, 01 Mar 2006 10:04:47 +0000
changeset 1989 d276e88aa48a
parent 1956 a055123339d5
permissions -rw-r--r--
Traits for alteration notifiers
SplitGraph is temporarly deleted
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@1989
    71
deba@1989
    72
  class InvalidType {
deba@1989
    73
  private:
deba@1989
    74
    InvalidType();
deba@1696
    75
  };
deba@1696
    76
  
deba@1696
    77
klao@977
    78
  template <typename T>
klao@977
    79
  struct Wrap {
klao@977
    80
    const T &value;
klao@977
    81
    Wrap(const T &t) : value(t) {}
klao@977
    82
  };
klao@977
    83
alpar@1256
    84
  /**************** dummy class to avoid ambiguity ****************/
klao@977
    85
alpar@1256
    86
  template<int T> struct dummy { dummy(int) {} };
klao@977
    87
klao@977
    88
  /**************** enable_if from BOOST ****************/
klao@977
    89
 
klao@977
    90
  template <bool B, class T = void>
klao@977
    91
  struct enable_if_c {
klao@977
    92
    typedef T type;
klao@977
    93
  };
klao@977
    94
klao@977
    95
  template <class T>
klao@977
    96
  struct enable_if_c<false, T> {};
klao@977
    97
klao@977
    98
  template <class Cond, class T = void> 
klao@977
    99
  struct enable_if : public enable_if_c<Cond::value, T> {};
klao@977
   100
klao@977
   101
  template <bool B, class T>
klao@977
   102
  struct lazy_enable_if_c {
klao@977
   103
    typedef typename T::type type;
klao@977
   104
  };
klao@977
   105
klao@977
   106
  template <class T>
klao@977
   107
  struct lazy_enable_if_c<false, T> {};
klao@977
   108
klao@977
   109
  template <class Cond, class T> 
klao@977
   110
  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
klao@977
   111
klao@977
   112
klao@977
   113
  template <bool B, class T = void>
klao@977
   114
  struct disable_if_c {
klao@977
   115
    typedef T type;
klao@977
   116
  };
klao@977
   117
klao@977
   118
  template <class T>
klao@977
   119
  struct disable_if_c<true, T> {};
klao@977
   120
klao@977
   121
  template <class Cond, class T = void> 
klao@977
   122
  struct disable_if : public disable_if_c<Cond::value, T> {};
klao@977
   123
klao@977
   124
  template <bool B, class T>
klao@977
   125
  struct lazy_disable_if_c {
klao@977
   126
    typedef typename T::type type;
klao@977
   127
  };
klao@977
   128
klao@977
   129
  template <class T>
klao@977
   130
  struct lazy_disable_if_c<true, T> {};
klao@977
   131
klao@977
   132
  template <class Cond, class T> 
klao@977
   133
  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
klao@977
   134
klao@977
   135
} // namespace lemon
klao@977
   136
klao@977
   137
#endif