1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/lemon/utility.h Wed Nov 10 20:14:32 2004 +0000
1.3 @@ -0,0 +1,110 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * src/lemon/utility.h - Part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi
1.9 + * Kutatocsoport (Egervary Combinatorial Optimization Research Group,
1.10 + * EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + * This file contains a modified version of the enable_if library from BOOST.
1.21 + * See the appropriate copyright notice below.
1.22 + */
1.23 +
1.24 +// Boost enable_if library
1.25 +
1.26 +// Copyright 2003 © The Trustees of Indiana University.
1.27 +
1.28 +// Use, modification, and distribution is subject to the Boost Software
1.29 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.30 +// http://www.boost.org/LICENSE_1_0.txt)
1.31 +
1.32 +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
1.33 +// Jeremiah Willcock (jewillco at osl.iu.edu)
1.34 +// Andrew Lumsdaine (lums at osl.iu.edu)
1.35 +
1.36 +
1.37 +#ifndef LEMON_UTILITY_H
1.38 +#define LEMON_UTILITY_H
1.39 +
1.40 +namespace lemon
1.41 +{
1.42 +
1.43 + /// Basic type for defining "tags". A "YES" condidion for enable_if.
1.44 +
1.45 + /// \todo This should go to a separate "basic_types.h" (or something)
1.46 + /// file.
1.47 + struct True {
1.48 + static const bool value = true;
1.49 + };
1.50 +
1.51 + /// Basic type for defining "tags". A "NO" condidion for enable_if.
1.52 + struct False {
1.53 + static const bool value = false;
1.54 + };
1.55 +
1.56 + template <typename T>
1.57 + struct Wrap {
1.58 + const T &value;
1.59 + Wrap(const T &t) : value(t) {}
1.60 + };
1.61 +
1.62 +
1.63 +
1.64 + /**************** enable_if from BOOST ****************/
1.65 +
1.66 + template <bool B, class T = void>
1.67 + struct enable_if_c {
1.68 + typedef T type;
1.69 + };
1.70 +
1.71 + template <class T>
1.72 + struct enable_if_c<false, T> {};
1.73 +
1.74 + template <class Cond, class T = void>
1.75 + struct enable_if : public enable_if_c<Cond::value, T> {};
1.76 +
1.77 + template <bool B, class T>
1.78 + struct lazy_enable_if_c {
1.79 + typedef typename T::type type;
1.80 + };
1.81 +
1.82 + template <class T>
1.83 + struct lazy_enable_if_c<false, T> {};
1.84 +
1.85 + template <class Cond, class T>
1.86 + struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
1.87 +
1.88 +
1.89 + template <bool B, class T = void>
1.90 + struct disable_if_c {
1.91 + typedef T type;
1.92 + };
1.93 +
1.94 + template <class T>
1.95 + struct disable_if_c<true, T> {};
1.96 +
1.97 + template <class Cond, class T = void>
1.98 + struct disable_if : public disable_if_c<Cond::value, T> {};
1.99 +
1.100 + template <bool B, class T>
1.101 + struct lazy_disable_if_c {
1.102 + typedef typename T::type type;
1.103 + };
1.104 +
1.105 + template <class T>
1.106 + struct lazy_disable_if_c<true, T> {};
1.107 +
1.108 + template <class Cond, class T>
1.109 + struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
1.110 +
1.111 +} // namespace lemon
1.112 +
1.113 +#endif