From 658f65d3d3186322c36e7408e1c0a5696c3ddf81 Mon Sep 17 00:00:00 2001 From: humesikkins Date: Wed, 5 Mar 2003 23:39:15 +0000 Subject: [PATCH] Changed default values for return types to void git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@113 7ec92016-0320-0410-acc4-a06ded1c099a --- MSVC/1200/MultiMethods.h | 20 ++++-- MSVC/1200/Visitor.h | 145 ++++++++++++++++++++------------------- 2 files changed, 86 insertions(+), 79 deletions(-) diff --git a/MSVC/1200/MultiMethods.h b/MSVC/1200/MultiMethods.h index 0655603..8eafedc 100644 --- a/MSVC/1200/MultiMethods.h +++ b/MSVC/1200/MultiMethods.h @@ -13,7 +13,8 @@ // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// -// Last update: Feb 19, 2003 +// Last update: Mar 06, 2003 +// All dispatchers now have void as default value for return types. // All dispatchers now support void as return type. // // @@ -208,7 +209,8 @@ namespace Private bool symmetric = true, class BaseRhs = BaseLhs, class TypesRhs = TypesLhs, - typename ResultType = int + typename ResultType = Loki::Select< + Loki::Private::AlwaysFalse::value, void, void>::Result > class StaticDispatcher : public ::Loki::Select < @@ -344,7 +346,8 @@ namespace Private < class BaseLhs, class BaseRhs = BaseLhs, - typename ResultType = int, + typename ResultType = Loki::Select< + Loki::Private::AlwaysFalse::value, void, void>::Result, typename CallbackType = ResultType (*)(BaseLhs&, BaseRhs&) > class BasicDispatcher : public ::Loki::Select @@ -511,7 +514,8 @@ namespace Private //////////////////////////////////////////////////////////////////////////////// template ::value, void, void>::Result, class CastingPolicy = DynamicCasterWrapper, class DispatcherBackend = BasicDispatcherWrapper> class FnDispatcher : public ::Loki::Select @@ -698,7 +702,8 @@ namespace Private //////////////////////////////////////////////////////////////////////////////// template ::value, void, void>::Result, class CastingPolicy = DynamicCasterWrapper, class DispatcherBackend = BasicDispatcherWrapper> class FunctorDispatcher : public ::Loki::Select @@ -776,9 +781,10 @@ namespace Private // Change log: // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! // May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466) -// Oct 28, 2002: ported by Benjamin Kaufmann +// Oct 28, 2002: ported by Benjamin Kaufmann to MSVC 6 // Feb 19, 2003: replaced pointer-Dummies with Type2Type-Parameters and added -// support for return type void. +// support for return type void. B.K. +// Mar 06, 2003: Changed default values for return types to void B.K. //////////////////////////////////////////////////////////////////////////////// #endif diff --git a/MSVC/1200/Visitor.h b/MSVC/1200/Visitor.h index f7d2f71..1e46f6f 100644 --- a/MSVC/1200/Visitor.h +++ b/MSVC/1200/Visitor.h @@ -2,32 +2,32 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The author or Addison-Wesley Longman make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The author or Addison-Wesley Longman make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// -// Last update: Feb 23, 2003 +// Last update: Mar 06, 2003 +// +// Like the original library, this port now uses void as +// default value for return types. // // This new of visitor.h handles void returns transparently. See // readme.txt for an explanation of the used technique. // However there are still two sets of macros. One for return type = void // (DEFINE_VISITABLE_VOID, DEFINE_CYCLIC_VISITABLE_VOID) and one for return // type != void (DEFINE_VISITABLE, DEFINE_CYCLIC_VISITABLE) -// +// // If you prefer the old version of visitor.h which uses a different set of -// visitor classes for the return type void, define the macro +// visitor classes for the return type void, define the macro // USE_VISITOR_OLD_VERSION. -// -// The MSVC 6.0 does not allow void to be a default value for a template parameter. -// I therefore changed all defaults to int. - +// #ifdef USE_VISITOR_OLD_VERSION #include "VisitorOld.h" #else @@ -51,21 +51,21 @@ namespace Loki public: virtual ~BaseVisitor() {} }; - + //////////////////////////////////////////////////////////////////////////////// // class template Visitor // The building block of Acyclic Visitor //////////////////////////////////////////////////////////////////////////////// - template + template class Visitor; //////////////////////////////////////////////////////////////////////////////// // class template Visitor (specialization) // This specialization is not present in the book. It makes it easier to define // Visitors for multiple types in a shot by using a typelist. Example: // -// class SomeVisitor : +// class SomeVisitor : // public BaseVisitor // required -// public Visitor, +// public Visitor, // public Visitor // { // public: @@ -77,7 +77,7 @@ namespace Private { // helper for Visitor's the left base class template - struct VisitorImplLeft + struct VisitorImplLeft { template struct In @@ -85,7 +85,7 @@ namespace Private typedef typename TList::ERROR_WRONG_SPECIALIZATION_SELECTED Result; }; }; - + // helper for Visitor's the right base class template struct VisitorImplRight @@ -97,7 +97,7 @@ namespace Private }; }; - // simulates specialization + // simulates specialization // class Visitor template <> struct VisitorImplLeft @@ -112,8 +112,8 @@ namespace Private }; }; }; - - // simulates the left base class for the specialization + + // simulates the left base class for the specialization // class Visitor, R> template <> struct VisitorImplLeft @@ -134,8 +134,8 @@ namespace Private struct Result {}; }; }; - - // simulates the right base class for the specialization + + // simulates the right base class for the specialization // class Visitor, R> template <> struct VisitorImplRight @@ -146,7 +146,7 @@ namespace Private typedef Visitor Result; }; }; - + template <> struct VisitorImplRight { @@ -156,7 +156,7 @@ namespace Private struct Result {}; }; }; - + // MSVC 6.0 will complain if we try to let Visitor inherit // directly from VisitorImplLeft/VisitorImplRight template @@ -166,14 +166,14 @@ namespace Private typedef typename VisitorImplLeft < TL::Private::IsTypelist::type_id == TL::Private::AtomList_ID ? - TL::Private::Typelist_ID : + TL::Private::Typelist_ID : TL::Private::IsTypelist::type_id >::template In::Result TempType; - + typedef VC_Base_Workaround Workaround; typedef Workaround::LeftBase Result; }; - + template struct VisitorImplRightWrap { @@ -182,70 +182,71 @@ namespace Private < TL::Private::IsTypelist::type_id >::template In::Result TempType; - + typedef VC_Base_Workaround Workaround; typedef Workaround::LeftBase Result; }; - + } template - class Visitor : public Private::VisitorImplLeftWrap::Result, + class Visitor : public Private::VisitorImplLeftWrap::Result, public Private::VisitorImplRightWrap::Result - + { public: typedef R ReturnType; }; - + //////////////////////////////////////////////////////////////////////////////// // class template BaseVisitorImpl // Implements non-strict visitation (you can implement only part of the Visit // functions) //////////////////////////////////////////////////////////////////////////////// - template class BaseVisitorImpl; + template + class BaseVisitorImpl; namespace Private { template struct BaseVisitorImplHelper { template - struct In - { - typedef typename T::ERROR_WRONG_SPECIALIZATION_SELECTED Result; + struct In + { + typedef typename T::ERROR_WRONG_SPECIALIZATION_SELECTED Result; }; }; - template<> + template<> struct BaseVisitorImplHelper { template - struct In - { - typedef BaseVisitorImpl Result; + struct In + { + typedef BaseVisitorImpl Result; }; }; - template<> + template<> struct BaseVisitorImplHelper { template - struct In - { - struct Result {}; + struct In + { + struct Result {}; }; }; - - template + + template struct BaseVisitorImplWrap - { + { struct Dummy {}; typedef typename BaseVisitorImplHelper < TL::Private::IsTypelist:: - type_id == TL::Private::AtomList_ID ? - TL::Private::Typelist_ID : + type_id == TL::Private::AtomList_ID ? + TL::Private::Typelist_ID : TL::Private::IsTypelist::type_id >::template In::Result TempType; typedef VC_Base_Workaround Workaround; @@ -265,11 +266,11 @@ namespace Private struct BaseVisitorImplVoidBase : public Visitor, public Private::BaseVisitorImplWrap::Result { - + ASSERT_TYPELIST(TList); virtual R Visit(typename TList::Head&) { } - }; + }; } @@ -293,7 +294,7 @@ namespace Private //////////////////////////////////////////////////////////////////////////////// namespace Private { - + } template struct DefaultCatchAll @@ -343,7 +344,7 @@ struct DefaultCatchAllWrapper ReturnType Visit(T&) {} }; - + struct NonStrictVisitorUnitWrapper { template @@ -358,18 +359,17 @@ struct DefaultCatchAllWrapper }; - template - class NonStrictVisitor + template + class NonStrictVisitor : public GenLinearHierarchy< - TList, - NonStrictVisitorUnitWrapper, + TList, + NonStrictVisitorUnitWrapper, Visitor > { }; //////////////////////////////////////////////////////////////////////////////// // class template BaseVisitable //////////////////////////////////////////////////////////////////////////////// -#include namespace Private { template @@ -382,7 +382,7 @@ namespace Private { typedef ApplyInnerType2::type CatchA; // Apply the Acyclic Visitor - if (Visitor* p = dynamic_cast*>(&guest)) + if (Visitor* p = dynamic_cast*>(&guest)) { return p->Visit(visited); } @@ -392,14 +392,14 @@ namespace Private template class BaseVisitableVoidBase { - typedef R ReturnType; - protected: + typedef R ReturnType; + protected: template static ReturnType AcceptImpl(T& visited, BaseVisitor& guest) { typedef ApplyInnerType2::type CatchA; // Apply the Acyclic Visitor - if (Visitor* p = dynamic_cast*>(&guest)) + if (Visitor* p = dynamic_cast*>(&guest)) { p->Visit(visited); return; @@ -408,9 +408,9 @@ namespace Private } }; } - template + template < - typename R = int/* = void */, + typename R = Loki::Private::VoidWrap::type, class CatchAll = DefaultCatchAllWrapper > class BaseVisitable : public Select::value, @@ -427,7 +427,7 @@ namespace Private //////////////////////////////////////////////////////////////////////////////// // macro DEFINE_VISITABLE -// Put it in every class that you want to make visitable (in addition to +// Put it in every class that you want to make visitable (in addition to // deriving it from BaseVisitable //////////////////////////////////////////////////////////////////////////////// @@ -441,7 +441,7 @@ namespace Private //////////////////////////////////////////////////////////////////////////////// // class template CyclicVisitor -// Put it in every class that you want to make visitable (in addition to +// Put it in every class that you want to make visitable (in addition to // deriving it from BaseVisitable //////////////////////////////////////////////////////////////////////////////// namespace Private @@ -479,10 +479,10 @@ namespace Private public: typedef R ReturnType; // using Visitor::Visit; - - + + }; - + //////////////////////////////////////////////////////////////////////////////// // macro DEFINE_CYCLIC_VISITABLE // Put it in every class that you want to make visitable by a cyclic visitor @@ -503,8 +503,9 @@ namespace Private // March 20: add default argument DefaultCatchAll to BaseVisitable // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! // Oct 27, 2002: ported by Benjamin Kaufmann to MSVC 6.0 -// Feb 23, 2003: Removed special visitor classes for return type void. +// Feb 23, 2003: Removed special visitor classes for return type void. // Added Loki:: qualification to Accept's Paramter (in the macro) B.K. +// Mar 06, 2003: Changed default values for return types to void B.K. //////////////////////////////////////////////////////////////////////////////// #endif // VISITOR_INC_