toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] tag/tag stdpp.h


From: Edward Rosten
Subject: [Toon-members] tag/tag stdpp.h
Date: Wed, 12 Jul 2006 00:26:37 +0000

CVSROOT:        /cvsroot/toon
Module name:    tag
Changes by:     Edward Rosten <edrosten>        06/07/12 00:26:37

Modified files:
        tag            : stdpp.h 

Log message:
        Utility function for std::pair, so that multiple values can be returned 
from
        functions directly in to two variables, eg:
        float f;
        int i;
        rpair(f, i) = make_pair(2.2f, 7);

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/tag/tag/stdpp.h?cvsroot=toon&r1=1.5&r2=1.6

Patches:
Index: stdpp.h
===================================================================
RCS file: /cvsroot/toon/tag/tag/stdpp.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- stdpp.h     4 Jun 2006 12:08:35 -0000       1.5
+++ stdpp.h     12 Jul 2006 00:26:37 -0000      1.6
@@ -2,6 +2,7 @@
 #define TAG_STDPP_H
 
 #include <iostream>
+#include <utility>
 
 namespace tag {
 
@@ -180,6 +181,45 @@
 
 #endif
 
+#ifndef DOXYGEN_IGNORE_INTERNAL
+namespace Internal
+{
+       template<class A, class B> struct refpair
+       {
+               A& a;
+               B& b;
+               refpair(A& aa, B& bb)
+               :a(aa),b(bb)
+               {}
+
+               void operator=(const std::pair<A,B>& p)
+               {
+                       a=p.first;
+                       b=p.second;
+               }
+       };
+}
+
+#endif
+
+/**
+Similar to <code>std::make_pair</code>, but for references. This can be used
+for multiple return values:
address@hidden
+float f;
+int i;
+rpair(f,i) = make_pair(2.2f, 1);
address@hidden
address@hidden aa first value
address@hidden bb second value
+**/
+template<class A, class B> Internal::refpair<A,B> rpair(A&aa, B&bb)
+{
+       return Internal::refpair<A,B>(aa, bb);
+}
+
+
+
 } // namespace tag
 
 #endif // __PRINT_H_




reply via email to

[Prev in Thread] Current Thread [Next in Thread]