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