klao@977: /* -*- C++ -*- ladanyi@1435: * lemon/utility.h - Part of LEMON, a generic C++ optimization library klao@977: * alpar@1164: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi alpar@1359: * Kutatocsoport (Egervary Research Group on Combinatorial Optimization, klao@977: * EGRES). klao@977: * klao@977: * Permission to use, modify and distribute this software is granted klao@977: * provided that this copyright notice appears in all copies. For klao@977: * precise terms see the accompanying LICENSE file. klao@977: * klao@977: * This software is provided "AS IS" with no warranty of any kind, klao@977: * express or implied, and with no claim as to its suitability for any klao@977: * purpose. klao@977: * klao@977: * This file contains a modified version of the enable_if library from BOOST. klao@977: * See the appropriate copyright notice below. klao@977: */ klao@977: klao@977: // Boost enable_if library klao@977: klao@977: // Copyright 2003 © The Trustees of Indiana University. klao@977: klao@977: // Use, modification, and distribution is subject to the Boost Software klao@977: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at klao@977: // http://www.boost.org/LICENSE_1_0.txt) klao@977: klao@977: // Authors: Jaakko Järvi (jajarvi at osl.iu.edu) klao@977: // Jeremiah Willcock (jewillco at osl.iu.edu) klao@977: // Andrew Lumsdaine (lums at osl.iu.edu) klao@977: klao@977: klao@977: #ifndef LEMON_UTILITY_H klao@977: #define LEMON_UTILITY_H klao@977: klao@977: namespace lemon klao@977: { klao@977: jacint@1270: /// Basic type for defining "tags". A "YES" condition for enable_if. klao@977: klao@977: /// \todo This should go to a separate "basic_types.h" (or something) klao@977: /// file. klao@977: struct True { klao@977: static const bool value = true; klao@977: }; klao@977: jacint@1270: /// Basic type for defining "tags". A "NO" condition for enable_if. klao@977: struct False { klao@977: static const bool value = false; klao@977: }; klao@977: klao@977: template klao@977: struct Wrap { klao@977: const T &value; klao@977: Wrap(const T &t) : value(t) {} klao@977: }; klao@977: alpar@1256: /**************** dummy class to avoid ambiguity ****************/ klao@977: alpar@1256: template struct dummy { dummy(int) {} }; klao@977: klao@977: /**************** enable_if from BOOST ****************/ klao@977: klao@977: template klao@977: struct enable_if_c { klao@977: typedef T type; klao@977: }; klao@977: klao@977: template klao@977: struct enable_if_c {}; klao@977: klao@977: template klao@977: struct enable_if : public enable_if_c {}; klao@977: klao@977: template klao@977: struct lazy_enable_if_c { klao@977: typedef typename T::type type; klao@977: }; klao@977: klao@977: template klao@977: struct lazy_enable_if_c {}; klao@977: klao@977: template klao@977: struct lazy_enable_if : public lazy_enable_if_c {}; klao@977: klao@977: klao@977: template klao@977: struct disable_if_c { klao@977: typedef T type; klao@977: }; klao@977: klao@977: template klao@977: struct disable_if_c {}; klao@977: klao@977: template klao@977: struct disable_if : public disable_if_c {}; klao@977: klao@977: template klao@977: struct lazy_disable_if_c { klao@977: typedef typename T::type type; klao@977: }; klao@977: klao@977: template klao@977: struct lazy_disable_if_c {}; klao@977: klao@977: template klao@977: struct lazy_disable_if : public lazy_disable_if_c {}; klao@977: deba@1418: // smart referencing deba@1418: deba@1418: template deba@1418: struct SmartReference { deba@1418: typedef _Type& Type; deba@1418: }; deba@1418: deba@1418: template deba@1418: struct SmartReference< deba@1418: _Type, deba@1418: typename enable_if::type deba@1418: > { deba@1418: typedef _Type Type; deba@1418: }; deba@1418: deba@1418: template deba@1418: struct SmartConstReference { deba@1418: typedef const _Type& Type; deba@1418: }; deba@1418: deba@1418: template deba@1418: struct SmartConstReference< deba@1418: _Type, deba@1418: typename enable_if::type deba@1418: > { deba@1418: typedef const _Type Type; deba@1418: }; deba@1418: deba@1418: template deba@1418: struct SmartParameter { deba@1418: typedef _Type& Type; deba@1418: }; deba@1418: deba@1418: template deba@1418: struct SmartParameter< deba@1418: _Type, deba@1418: typename enable_if::type deba@1418: > { deba@1418: typedef const _Type& Type; deba@1418: }; deba@1418: klao@977: } // namespace lemon klao@977: klao@977: #endif