# HG changeset patch
# User deba
# Date 1155308133 0
# Node ID 416a7030b7e377746634e05ae477b3173758269f
# Parent  0f647e65ecad0f3a1646edb7fcc67a444410ea89
BiVariant moved to lemon/bits/variant.h

diff -r 0f647e65ecad -r 416a7030b7e3 lemon/Makefile.am
--- a/lemon/Makefile.am	Fri Aug 11 14:55:02 2006 +0000
+++ b/lemon/Makefile.am	Fri Aug 11 14:55:33 2006 +0000
@@ -110,6 +110,7 @@
 	lemon/bits/mingw32_time.h \
 	lemon/bits/traits.h \
 	lemon/bits/utility.h \
+	lemon/bits/variant.h \
 	lemon/bits/vector_map.h
 
 concept_HEADERS += \
diff -r 0f647e65ecad -r 416a7030b7e3 lemon/bits/utility.h
--- a/lemon/bits/utility.h	Fri Aug 11 14:55:02 2006 +0000
+++ b/lemon/bits/utility.h	Fri Aug 11 14:55:33 2006 +0000
@@ -35,8 +35,6 @@
 #ifndef LEMON_BITS_UTILITY_H
 #define LEMON_BITS_UTILITY_H
 
-#include <lemon/error.h>
-
 ///\file
 ///\brief Miscellaneous basic utilities
 ///
@@ -76,216 +74,6 @@
     InvalidType();
   };
 
-  template <bool left, bool right>
-  struct CTOr {
-    static const bool value = true;
-  };
-
-  template <>
-  struct CTOr<false, false> {
-    static const bool value = false;
-  };
-
-  template <bool left, bool right>
-  struct CTAnd {
-    static const bool value = false;
-  };
-
-  template <>
-  struct CTAnd<true, true> {
-    static const bool value = true;
-  };
-
-  template <int left, int right>
-  struct CTEqual {
-    static const bool value = false;
-  };
-
-  template <int val>
-  struct CTEqual<val, val> {
-    static const bool value = true;
-  };
-
-
-  template <int left, int right>
-  struct CTLess {
-    static const bool value = left < right;
-  };
-
-  template <int left>
-  struct CTLess<left, 0> {
-    static const bool value = false;
-  };
-
-  template <int right>
-  struct CTLess<0, right> {
-    static const bool value = true;
-  };
-
-  template <>
-  struct CTLess<0, 0> {
-    static const bool value = false;
-  };
-
-  template <>
-  struct CTLess<1, 1> {
-    static const bool value = false;
-  };
-
-  template <bool less, int left, int right>
-  struct CTMaxImpl {
-    static const int value = left;    
-  };
-
-  template <int left, int right>
-  struct CTMaxImpl<true, left, right> {
-    static const int value = right;
-  };
-  
-  template <int left, int right>
-  struct CTMax {
-    static const int value = 
-    CTMaxImpl<CTLess<left, right>::value, left, right>::value;
-  };
-
-
-  /// \brief Simple Variant type with two type
-  ///
-  /// Simple Variant type with two type
-  template <typename _First, typename _Second>
-  class BiVariant {
-  public:
-
-    typedef _First First;
-    typedef _Second Second;
-
-    struct WrongStateError : public lemon::LogicError {
-    public:
-      virtual const char* what() const throw() {
-        return "lemon::BiVariant::WrongStateError";
-      }
-    };
-
-    BiVariant() {
-      flag = true;
-      new(reinterpret_cast<First*>(data)) First();
-    }
-
-    BiVariant(const First& first) {
-      flag = true;
-      new(reinterpret_cast<First*>(data)) First(first);
-    }
-
-    BiVariant(const Second& second) {
-      flag = false;
-      new(reinterpret_cast<Second*>(data)) Second(second);
-    }
-
-    BiVariant(const BiVariant& bivariant) {
-      flag = bivariant.flag;
-      if (flag) {
-        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
-      } else {
-        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
-      }
-    }
-
-    ~BiVariant() {
-      destroy();
-    }
-
-    BiVariant& setFirst() {
-      destroy();
-      flag = true;
-      new(reinterpret_cast<First*>(data)) First();   
-      return *this;
-    }
-
-    BiVariant& setFirst(const First& first) {
-      destroy();
-      flag = true;
-      new(reinterpret_cast<First*>(data)) First(first);   
-      return *this;
-    }
-
-    BiVariant& setSecond() {
-      destroy();
-      flag = false;
-      new(reinterpret_cast<Second*>(data)) Second();   
-      return *this;
-    }
-
-    BiVariant& setSecond(const Second& second) {
-      destroy();
-      flag = false;
-      new(reinterpret_cast<Second*>(data)) Second(second);   
-      return *this;
-    }
-
-    BiVariant& operator=(const First& first) {
-      return setFirst(first);
-    }
-
-    BiVariant& operator=(const Second& second) {
-      return setSecond(second);
-    }
-
-
-    BiVariant& operator=(const BiVariant& bivariant) {
-      if (this == &bivariant) return *this;
-      destroy();
-      flag = bivariant.flag;
-      if (flag) {
-        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
-      } else {
-        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
-      }
-      return *this;
-    }
-
-    First& first() {
-      LEMON_ASSERT(flag, WrongStateError());
-      return *reinterpret_cast<First*>(data); 
-    }
-
-    const First& first() const { 
-      LEMON_ASSERT(flag, WrongStateError());
-      return *reinterpret_cast<const First*>(data); 
-    }
-
-    operator First&() { return first(); }
-    operator const First&() const { return first(); }
-
-    Second& second() { 
-      LEMON_ASSERT(!flag, WrongStateError());
-      return *reinterpret_cast<Second*>(data); 
-    }
-
-    const Second& second() const { 
-      LEMON_ASSERT(!flag, WrongStateError());
-      return *reinterpret_cast<const Second*>(data); 
-    }
-
-    operator Second&() { return second(); }
-    operator const Second&() const { return second(); }
-
-    bool firstState() const { return flag; }
-    bool secondState() const { return !flag; }
-
-  private:
-
-    void destroy() {
-      if (flag) {
-        reinterpret_cast<First*>(data)->~First();
-      } else {
-        reinterpret_cast<Second*>(data)->~Second();
-      }
-    }
-    
-    char data[CTMax<sizeof(First), sizeof(Second)>::value];
-    bool flag;
-  };
-
   template <typename T>
   struct Wrap {
     const T &value;
diff -r 0f647e65ecad -r 416a7030b7e3 lemon/bits/variant.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/bits/variant.h	Fri Aug 11 14:55:33 2006 +0000
@@ -0,0 +1,239 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BITS_VARIANT_H
+#define LEMON_BITS_VARIANT_H
+
+#include <lemon/error.h>
+
+namespace lemon {
+
+  template <bool left, bool right>
+  struct CTOr {
+    static const bool value = true;
+  };
+
+  template <>
+  struct CTOr<false, false> {
+    static const bool value = false;
+  };
+
+  template <bool left, bool right>
+  struct CTAnd {
+    static const bool value = false;
+  };
+
+  template <>
+  struct CTAnd<true, true> {
+    static const bool value = true;
+  };
+
+  template <int left, int right>
+  struct CTEqual {
+    static const bool value = false;
+  };
+
+  template <int val>
+  struct CTEqual<val, val> {
+    static const bool value = true;
+  };
+
+
+  template <int left, int right>
+  struct CTLess {
+    static const bool value = left < right;
+  };
+
+  template <int left>
+  struct CTLess<left, 0> {
+    static const bool value = false;
+  };
+
+  template <int right>
+  struct CTLess<0, right> {
+    static const bool value = true;
+  };
+
+  template <>
+  struct CTLess<0, 0> {
+    static const bool value = false;
+  };
+
+  template <>
+  struct CTLess<1, 1> {
+    static const bool value = false;
+  };
+
+  template <bool less, int left, int right>
+  struct CTMaxImpl {
+    static const int value = left;    
+  };
+
+  template <int left, int right>
+  struct CTMaxImpl<true, left, right> {
+    static const int value = right;
+  };
+  
+  template <int left, int right>
+  struct CTMax {
+    static const int value = 
+    CTMaxImpl<CTLess<left, right>::value, left, right>::value;
+  };
+
+
+  /// \brief Simple Variant type with two type
+  ///
+  /// Simple Variant type with two type
+  template <typename _First, typename _Second>
+  class BiVariant {
+  public:
+
+    typedef _First First;
+    typedef _Second Second;
+
+    struct WrongStateError : public lemon::LogicError {
+    public:
+      virtual const char* what() const throw() {
+        return "lemon::BiVariant::WrongStateError";
+      }
+    };
+
+    BiVariant() {
+      flag = true;
+      new(reinterpret_cast<First*>(data)) First();
+    }
+
+    BiVariant(const First& first) {
+      flag = true;
+      new(reinterpret_cast<First*>(data)) First(first);
+    }
+
+    BiVariant(const Second& second) {
+      flag = false;
+      new(reinterpret_cast<Second*>(data)) Second(second);
+    }
+
+    BiVariant(const BiVariant& bivariant) {
+      flag = bivariant.flag;
+      if (flag) {
+        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
+      } else {
+        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
+      }
+    }
+
+    ~BiVariant() {
+      destroy();
+    }
+
+    BiVariant& setFirst() {
+      destroy();
+      flag = true;
+      new(reinterpret_cast<First*>(data)) First();   
+      return *this;
+    }
+
+    BiVariant& setFirst(const First& first) {
+      destroy();
+      flag = true;
+      new(reinterpret_cast<First*>(data)) First(first);   
+      return *this;
+    }
+
+    BiVariant& setSecond() {
+      destroy();
+      flag = false;
+      new(reinterpret_cast<Second*>(data)) Second();   
+      return *this;
+    }
+
+    BiVariant& setSecond(const Second& second) {
+      destroy();
+      flag = false;
+      new(reinterpret_cast<Second*>(data)) Second(second);   
+      return *this;
+    }
+
+    BiVariant& operator=(const First& first) {
+      return setFirst(first);
+    }
+
+    BiVariant& operator=(const Second& second) {
+      return setSecond(second);
+    }
+
+
+    BiVariant& operator=(const BiVariant& bivariant) {
+      if (this == &bivariant) return *this;
+      destroy();
+      flag = bivariant.flag;
+      if (flag) {
+        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
+      } else {
+        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
+      }
+      return *this;
+    }
+
+    First& first() {
+      LEMON_ASSERT(flag, WrongStateError());
+      return *reinterpret_cast<First*>(data); 
+    }
+
+    const First& first() const { 
+      LEMON_ASSERT(flag, WrongStateError());
+      return *reinterpret_cast<const First*>(data); 
+    }
+
+    operator First&() { return first(); }
+    operator const First&() const { return first(); }
+
+    Second& second() { 
+      LEMON_ASSERT(!flag, WrongStateError());
+      return *reinterpret_cast<Second*>(data); 
+    }
+
+    const Second& second() const { 
+      LEMON_ASSERT(!flag, WrongStateError());
+      return *reinterpret_cast<const Second*>(data); 
+    }
+
+    operator Second&() { return second(); }
+    operator const Second&() const { return second(); }
+
+    bool firstState() const { return flag; }
+    bool secondState() const { return !flag; }
+
+  private:
+
+    void destroy() {
+      if (flag) {
+        reinterpret_cast<First*>(data)->~First();
+      } else {
+        reinterpret_cast<Second*>(data)->~Second();
+      }
+    }
+    
+    char data[CTMax<sizeof(First), sizeof(Second)>::value];
+    bool flag;
+  };
+
+}
+
+
+#endif
diff -r 0f647e65ecad -r 416a7030b7e3 lemon/graph_adaptor.h
--- a/lemon/graph_adaptor.h	Fri Aug 11 14:55:02 2006 +0000
+++ b/lemon/graph_adaptor.h	Fri Aug 11 14:55:33 2006 +0000
@@ -28,6 +28,7 @@
 ///\author Marton Makai and Balazs Dezso
 
 #include <lemon/bits/invalid.h>
+#include <lemon/bits/variant.h>
 #include <lemon/maps.h>
 
 #include <lemon/bits/base_extender.h>