|
From: <ag...@us...> - 2011-01-12 21:53:35
|
Revision: 1880
http://zoolib.svn.sourceforge.net/zoolib/?rev=1880&view=rev
Author: agreen
Date: 2011-01-12 21:53:29 +0000 (Wed, 12 Jan 2011)
Log Message:
-----------
Reorg, and add macros that make common uses of operator_bool
much less verbose and ugly.
Modified Paths:
--------------
trunk/zoolib/source/cxx/zoolib/ZCompat_operator_bool.h
Modified: trunk/zoolib/source/cxx/zoolib/ZCompat_operator_bool.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZCompat_operator_bool.h 2011-01-12 12:07:45 UTC (rev 1879)
+++ trunk/zoolib/source/cxx/zoolib/ZCompat_operator_bool.h 2011-01-12 21:53:29 UTC (rev 1880)
@@ -103,22 +103,30 @@
static return_type true_value()
{ return &class_type::i; }
-private:
- int i;
-public:
/// Returns the value representing the false condition
static return_type false_value()
{ return static_cast<return_type>(0); }
/// Does the ternary operator for you
- template <typename U>
- static return_type translate(U b)
+ template <typename O>
+ static return_type translate(const O& b)
{ return b ? true_value() : false_value(); }
private:
void operator delete(void*);
+ int i;
};
#endif
+#define ZMACRO_operator_bool(U, B) \
+ typedef operator_bool_generator<U>::class_type B##_gen; \
+ typedef B##_gen::return_type B; \
+ operator B()
+
+#define ZMACRO_operator_bool_T(U, B) \
+ typedef typename operator_bool_generator<U>::class_type B##_gen; \
+ typedef typename B##_gen::return_type B; \
+ operator B()
+
#endif // __ZCompat_operator_bool__
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|