|
From: <syn...@us...> - 2009-11-21 10:41:05
|
Revision: 1059
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1059&view=rev
Author: syntheticpp
Date: 2009-11-21 10:40:59 +0000 (Sat, 21 Nov 2009)
Log Message:
-----------
add foreach
Added Paths:
-----------
trunk/include/loki/ForEachType.h
Added: trunk/include/loki/ForEachType.h
===================================================================
--- trunk/include/loki/ForEachType.h (rev 0)
+++ trunk/include/loki/ForEachType.h 2009-11-21 10:40:59 UTC (rev 1059)
@@ -0,0 +1,101 @@
+
+////////////////////////////////////////////////////////////////////////////////
+// The Loki Library
+// Copyright (C) 2009 Andy Balaam
+// Copyright (c) 2009 Peter K\xFCmmel
+// 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 makes no representations about the
+// suitability of this software for any purpose. It is provided "as is"
+// without express or implied warranty.
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef LOKI_FOR_EACH_TYPE
+#define LOKI_FOR_EACH_TYPE
+
+#include <loki/NullType.h>
+#include <loki/Typelist.h>
+
+namespace Loki
+{
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // class template ForEachType
+ // Calls a templated callable for every element of a Typelist
+ // Supplies an int template parameter for the position in the TypeList.
+ // Invocation (TList is a typelist):
+ // ForEachType<TList> dummy();
+ // Calls the supplied method during construction of the object dummy.
+ ////////////////////////////////////////////////////////////////////////////////
+
+ namespace Private
+ {
+ // type of recursive function
+ template <class TList, class Callable>
+ struct ForEachTypeImpl;
+
+ // Recursion rule
+ template <class Head, class Tail, class Callable>
+ struct ForEachTypeImpl<Typelist<Head, Tail>, Callable>
+ : public ForEachTypeImpl<Tail, Callable>
+ {
+ enum { value = 1 + ForEachTypeImpl<Tail, Callable>::value };
+
+ ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable)
+ {
+ callable.operator()<value, Head>();
+ }
+
+ };
+
+ // Recursion end
+ template <class Head, class Callable>
+ struct ForEachTypeImpl<Typelist<Head, NullType>, Callable>
+ {
+ public:
+
+ enum { value = 0 };
+
+ ForEachTypeImpl( Callable& callable )
+ {
+ callable.operator()<value, Head>();
+ }
+ };
+
+
+ }
+
+
+ struct OrderPolicyForward;
+ struct OrderPolicyBackward;
+
+ template <class TList, class Callable, class OrderPolicy = OrderPolicyForward>
+ struct ForEachType;
+
+ template <class TList, class Callable >
+ struct ForEachType<TList, Callable, OrderPolicyForward>
+ : public Private::ForEachTypeImpl<typename TL::Reverse<TList>::Result, Callable >
+ {
+ ForEachType( Callable& callable )
+ : Private::ForEachTypeImpl<typename TL::Reverse<TList>::Result, Callable >( callable )
+ {
+ }
+ };
+
+ template <class TList, class Callable >
+ struct ForEachType<TList, Callable, OrderPolicyBackward>
+ : public Private::ForEachTypeImpl< TList, Callable >
+ {
+ ForEachType( Callable& callable )
+ : Private::ForEachTypeImpl< TList, Callable >( callable )
+ {
+ }
+ };
+
+
+}
+
+#endif
+
Property changes on: trunk/include/loki/ForEachType.h
___________________________________________________________________
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <syn...@us...> - 2009-11-21 10:47:20
|
Revision: 1062
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1062&view=rev
Author: syntheticpp
Date: 2009-11-21 10:47:12 +0000 (Sat, 21 Nov 2009)
Log Message:
-----------
utf8
Modified Paths:
--------------
trunk/include/loki/ForEachType.h
Modified: trunk/include/loki/ForEachType.h
===================================================================
--- trunk/include/loki/ForEachType.h 2009-11-21 10:44:43 UTC (rev 1061)
+++ trunk/include/loki/ForEachType.h 2009-11-21 10:47:12 UTC (rev 1062)
@@ -1,8 +1,8 @@
-
+
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (C) 2009 Andy Balaam
-// Copyright (c) 2009 Peter K\xFCmmel
+// Copyright (c) 2009 Peter Kümmel
// 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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <syn...@us...> - 2009-11-21 10:54:28
|
Revision: 1063
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1063&view=rev
Author: syntheticpp
Date: 2009-11-21 10:54:19 +0000 (Sat, 21 Nov 2009)
Log Message:
-----------
msvc doesn't understand this C++
Modified Paths:
--------------
trunk/include/loki/ForEachType.h
Modified: trunk/include/loki/ForEachType.h
===================================================================
--- trunk/include/loki/ForEachType.h 2009-11-21 10:47:12 UTC (rev 1062)
+++ trunk/include/loki/ForEachType.h 2009-11-21 10:54:19 UTC (rev 1063)
@@ -45,7 +45,11 @@
ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable)
{
+#ifdef _MSC_VER
callable.operator()<value, Head>();
+#else
+ callable.template operator()<value, Head>();
+#endif
}
};
@@ -60,7 +64,11 @@
ForEachTypeImpl( Callable& callable )
{
+#ifdef _MSC_VER
callable.operator()<value, Head>();
+#else
+ callable.template operator()<value, Head>();
+#endif
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <syn...@us...> - 2009-11-22 10:55:31
|
Revision: 1064
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1064&view=rev
Author: syntheticpp
Date: 2009-11-22 10:55:24 +0000 (Sun, 22 Nov 2009)
Log Message:
-----------
indent 4 spaces
Modified Paths:
--------------
trunk/include/loki/ForEachType.h
Modified: trunk/include/loki/ForEachType.h
===================================================================
--- trunk/include/loki/ForEachType.h 2009-11-21 10:54:19 UTC (rev 1063)
+++ trunk/include/loki/ForEachType.h 2009-11-22 10:55:24 UTC (rev 1064)
@@ -41,16 +41,16 @@
struct ForEachTypeImpl<Typelist<Head, Tail>, Callable>
: public ForEachTypeImpl<Tail, Callable>
{
- enum { value = 1 + ForEachTypeImpl<Tail, Callable>::value };
+ enum { value = 1 + ForEachTypeImpl<Tail, Callable>::value };
- ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable)
- {
+ ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable)
+ {
#ifdef _MSC_VER
- callable.operator()<value, Head>();
+ callable.operator()<value, Head>();
#else
- callable.template operator()<value, Head>();
+ callable.template operator()<value, Head>();
#endif
- }
+ }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|