diff --git a/lemon/bits/variant.h b/lemon/bits/variant.h --- a/lemon/bits/variant.h +++ b/lemon/bits/variant.h @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -27,7 +27,7 @@ namespace lemon { namespace _variant_bits { - + template struct CTMax { static const int value = left < right ? right : left; @@ -86,9 +86,9 @@ BiVariant(const BiVariant& bivariant) { flag = bivariant.flag; if (flag) { - new(reinterpret_cast(data)) First(bivariant.first()); + new(reinterpret_cast(data)) First(bivariant.first()); } else { - new(reinterpret_cast(data)) Second(bivariant.second()); + new(reinterpret_cast(data)) Second(bivariant.second()); } } @@ -106,7 +106,7 @@ BiVariant& setFirst() { destroy(); flag = true; - new(reinterpret_cast(data)) First(); + new(reinterpret_cast(data)) First(); return *this; } @@ -117,7 +117,7 @@ BiVariant& setFirst(const First& f) { destroy(); flag = true; - new(reinterpret_cast(data)) First(f); + new(reinterpret_cast(data)) First(f); return *this; } @@ -128,7 +128,7 @@ BiVariant& setSecond() { destroy(); flag = false; - new(reinterpret_cast(data)) Second(); + new(reinterpret_cast(data)) Second(); return *this; } @@ -139,7 +139,7 @@ BiVariant& setSecond(const Second& s) { destroy(); flag = false; - new(reinterpret_cast(data)) Second(s); + new(reinterpret_cast(data)) Second(s); return *this; } @@ -159,9 +159,9 @@ destroy(); flag = bivariant.flag; if (flag) { - new(reinterpret_cast(data)) First(bivariant.first()); + new(reinterpret_cast(data)) First(bivariant.first()); } else { - new(reinterpret_cast(data)) Second(bivariant.second()); + new(reinterpret_cast(data)) Second(bivariant.second()); } return *this; } @@ -231,13 +231,13 @@ reinterpret_cast(data)->~Second(); } } - + char data[_variant_bits::CTMax::value]; bool flag; }; namespace _variant_bits { - + template struct Memory { @@ -276,14 +276,14 @@ template struct Size { - static const int value = - CTMax::Type), + static const int value = + CTMax::Type), Size<_idx - 1, _TypeMap>::value>::value; }; template struct Size<0, _TypeMap> { - static const int value = + static const int value = sizeof(typename _TypeMap::template Map<0>::Type); }; @@ -301,7 +301,7 @@ /// \param _num The number of the types which can be stored in the /// variant type. /// \param _TypeMap This class describes the types of the Variant. The - /// _TypeMap::Map::Type should be a valid type for each index + /// _TypeMap::Map::Type should be a valid type for each index /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper /// class to define such type mappings up to 10 types. /// @@ -337,7 +337,7 @@ /// with 0 index. Variant() { flag = 0; - new(reinterpret_cast::Type*>(data)) + new(reinterpret_cast::Type*>(data)) typename TypeMap::template Map<0>::Type(); } @@ -378,7 +378,7 @@ Variant& set() { _variant_bits::Memory::destroy(flag, data); flag = _idx; - new(reinterpret_cast::Type*>(data)) + new(reinterpret_cast::Type*>(data)) typename TypeMap::template Map<_idx>::Type(); return *this; } @@ -391,7 +391,7 @@ Variant& set(const typename _TypeMap::template Map<_idx>::Type& init) { _variant_bits::Memory::destroy(flag, data); flag = _idx; - new(reinterpret_cast::Type*>(data)) + new(reinterpret_cast::Type*>(data)) typename TypeMap::template Map<_idx>::Type(init); return *this; } @@ -403,7 +403,7 @@ const typename TypeMap::template Map<_idx>::Type& get() const { LEMON_DEBUG(_idx == flag, "Variant wrong index"); return *reinterpret_cast::Type*>(data); + template Map<_idx>::Type*>(data); } /// \brief Gets the current value of the type with \c _idx index. @@ -413,7 +413,7 @@ typename _TypeMap::template Map<_idx>::Type& get() { LEMON_DEBUG(_idx == flag, "Variant wrong index"); return *reinterpret_cast::Type*> - (data); + (data); } /// \brief Returns the current state of the variant. @@ -424,7 +424,7 @@ } private: - + char data[_variant_bits::Size::value]; int flag; }; @@ -442,14 +442,14 @@ }; struct List {}; - + template struct Insert { typedef _List Next; typedef _Type Type; }; - template struct Mapper { @@ -466,7 +466,7 @@ typedef Insert<_T0, L1> L0; typedef typename Get<_idx, L0>::Type Type; }; - + } /// \brief Helper class for Variant @@ -475,7 +475,7 @@ /// converts the template parameters to be mappable by integer. /// \see Variant template < - typename _T0, + typename _T0, typename _T1 = void, typename _T2 = void, typename _T3 = void, typename _T5 = void, typename _T4 = void, typename _T6 = void, typename _T7 = void, typename _T8 = void, typename _T9 = void> @@ -487,7 +487,7 @@ Type; }; }; - + }