deba@220: /* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@220:  *
deba@220:  * This file is a part of LEMON, a generic C++ optimization library.
deba@220:  *
deba@220:  * Copyright (C) 2003-2008
deba@220:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@220:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@220:  *
deba@220:  * Permission to use, modify and distribute this software is granted
deba@220:  * provided that this copyright notice appears in all copies. For
deba@220:  * precise terms see the accompanying LICENSE file.
deba@220:  *
deba@220:  * This software is provided "AS IS" with no warranty of any kind,
deba@220:  * express or implied, and with no claim as to its suitability for any
deba@220:  * purpose.
deba@220:  *
deba@220:  */
deba@220: 
deba@220: // This file contains a modified version of the enable_if library from BOOST.
deba@220: // See the appropriate copyright notice below.
deba@220: 
deba@220: // Boost enable_if library
deba@220: 
deba@220: // Copyright 2003 (c) The Trustees of Indiana University.
deba@220: 
deba@220: // Use, modification, and distribution is subject to the Boost Software
deba@220: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
deba@220: // http://www.boost.org/LICENSE_1_0.txt)
deba@220: 
deba@220: //    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
deba@220: //             Jeremiah Willcock (jewillco at osl.iu.edu)
deba@220: //             Andrew Lumsdaine (lums at osl.iu.edu)
deba@220: 
deba@220: 
deba@220: #ifndef LEMON_BITS_ENABLE_IF_H
deba@220: #define LEMON_BITS_ENABLE_IF_H
deba@220: 
deba@220: ///\file
deba@220: ///\brief Miscellaneous basic utilities
deba@220: 
deba@220: namespace lemon
deba@220: {
deba@220: 
deba@220:   /// Basic type for defining "tags". A "YES" condition for \c enable_if.
deba@220: 
deba@220:   /// Basic type for defining "tags". A "YES" condition for \c enable_if.
deba@220:   ///
deba@220:   ///\sa False
deba@220:   struct True {
deba@220:     ///\e
deba@220:     static const bool value = true;
deba@220:   };
deba@220: 
deba@220:   /// Basic type for defining "tags". A "NO" condition for \c enable_if.
deba@220: 
deba@220:   /// Basic type for defining "tags". A "NO" condition for \c enable_if.
deba@220:   ///
deba@220:   ///\sa True
deba@220:   struct False {
deba@220:     ///\e
deba@220:     static const bool value = false;
deba@220:   };
deba@220: 
deba@220: 
deba@220: 
deba@220:   template <typename T>
deba@220:   struct Wrap {
deba@220:     const T &value;
deba@220:     Wrap(const T &t) : value(t) {}
deba@220:   };
deba@220: 
deba@220:   /**************** dummy class to avoid ambiguity ****************/
deba@220: 
deba@220:   template<int T> struct dummy { dummy(int) {} };
deba@220: 
deba@220:   /**************** enable_if from BOOST ****************/
deba@220: 
deba@220:   template <typename Type, typename T = void>
deba@220:   struct exists {
deba@220:     typedef T type;
deba@220:   };
deba@220: 
deba@220: 
deba@220:   template <bool B, class T = void>
deba@220:   struct enable_if_c {
deba@220:     typedef T type;
deba@220:   };
deba@220: 
deba@220:   template <class T>
deba@220:   struct enable_if_c<false, T> {};
deba@220: 
deba@220:   template <class Cond, class T = void>
deba@220:   struct enable_if : public enable_if_c<Cond::value, T> {};
deba@220: 
deba@220:   template <bool B, class T>
deba@220:   struct lazy_enable_if_c {
deba@220:     typedef typename T::type type;
deba@220:   };
deba@220: 
deba@220:   template <class T>
deba@220:   struct lazy_enable_if_c<false, T> {};
deba@220: 
deba@220:   template <class Cond, class T>
deba@220:   struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
deba@220: 
deba@220: 
deba@220:   template <bool B, class T = void>
deba@220:   struct disable_if_c {
deba@220:     typedef T type;
deba@220:   };
deba@220: 
deba@220:   template <class T>
deba@220:   struct disable_if_c<true, T> {};
deba@220: 
deba@220:   template <class Cond, class T = void>
deba@220:   struct disable_if : public disable_if_c<Cond::value, T> {};
deba@220: 
deba@220:   template <bool B, class T>
deba@220:   struct lazy_disable_if_c {
deba@220:     typedef typename T::type type;
deba@220:   };
deba@220: 
deba@220:   template <class T>
deba@220:   struct lazy_disable_if_c<true, T> {};
deba@220: 
deba@220:   template <class Cond, class T>
deba@220:   struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
deba@220: 
deba@220: } // namespace lemon
deba@220: 
deba@220: #endif