zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #13307
[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba
Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.
Requested reviews:
Paul J. Lucas (paul-lucas)
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/119730
Miscellaneous changes, some a prerequisite for LLVM that should be done anyway and not have to wait for the far-in-the-future LLVM branch merge.
--
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/119730
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/internal/unique_ptr.h'
--- include/zorba/internal/unique_ptr.h 2012-08-14 11:13:50 +0000
+++ include/zorba/internal/unique_ptr.h 2012-08-15 15:14:25 +0000
@@ -26,6 +26,7 @@
#include <algorithm> /* for swap() */
#include "type_traits.h"
+#include "ztd.h"
namespace std {
@@ -205,9 +206,7 @@
typedef typename ZORBA_TR1_NS::add_reference<D const>::type
deleter_const_reference;
- // see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2333.html
- struct pointer_conversion { int valid; };
- typedef int pointer_conversion::*explicit_bool;
+ typedef zorba::internal::ztd::explicit_bool explicit_bool;
public:
typedef T element_type;
@@ -408,8 +407,8 @@
* @return Returns \c true only if the pointer is not null; \c false only if
* the pointer is null.
*/
- operator explicit_bool() const throw() {
- return get() ? &pointer_conversion::valid : 0;
+ operator explicit_bool::type() const throw() {
+ return explicit_bool::value_of( get() );
}
private:
=== modified file 'include/zorba/internal/ztd.h'
--- include/zorba/internal/ztd.h 2012-08-14 11:13:50 +0000
+++ include/zorba/internal/ztd.h 2012-08-15 15:14:25 +0000
@@ -370,6 +370,56 @@
return s ? s : "<null>";
}
+////////// misc ///////////////////////////////////////////////////////////////
+
+/**
+ * Helper class for implementing a solution to the "explicit bool conversion"
+ * problem. The canonical use is of the form:
+ * \code
+ * class your_class {
+ * // ...
+ * operator explicit_bool::type() const {
+ * return explicit_bool::value_of( some_expression );
+ * }
+ * };
+ * \endcode
+ *
+ * See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2333.html
+ */
+class explicit_bool {
+ struct pointer_conversion { int valid; };
+public:
+ typedef int pointer_conversion::*type;
+
+ /**
+ * Gets the explicit \c bool value for \c false.
+ *
+ * @return Returns said value.
+ */
+ static type false_value() {
+ return 0;
+ }
+
+ /**
+ * Gets the explicit \c bool value for \c true.
+ *
+ * @return Returns said value.
+ */
+ static type true_value() {
+ return &pointer_conversion::valid;
+ }
+
+ /**
+ * Converts the the built-in \c bool value to an explicit \c bool value.
+ *
+ * @param value The \c bool value to convert.
+ * @return Return said value.
+ */
+ static type value_of( bool value ) {
+ return value ? true_value() : false_value();
+ }
+};
+
///////////////////////////////////////////////////////////////////////////////
} // namespace ztd
=== modified file 'src/util/stl_util.h'
--- src/util/stl_util.h 2012-08-14 11:13:50 +0000
+++ src/util/stl_util.h 2012-08-15 15:14:25 +0000
@@ -155,11 +155,13 @@
///////////////////////////////////////////////////////////////////////////////
/**
- * A less-verbose way to determine whether the given set<T> contains a
+ * A less-verbose way to determine whether the given map or set contains a
* particular element.
*/
-template<typename T> inline
-bool contains( std::set<T> const &s, typename call_traits<T>::arg_type v ) {
+template<class ContainerType> inline
+bool contains(
+ ContainerType const &s,
+ typename call_traits<typename ContainerType::key_type>::arg_type v ) {
return s.find( v ) != s.end();
}
@@ -200,8 +202,32 @@
}
/**
- * Erases the first element in the given sequence for which the given predicate
- * is \c true.
+ * Erases all elements in the given container for which the given predicate is
+ * \c true.
+ *
+ * @tparam SequenceType The sequence type.
+ * @tparam PredicateType The predicate type.
+ * @param seq The sequence to modify.
+ * @param pred The predicate to use.
+ * @return Returns the number of elements erased.
+ */
+template<class SequenceType,class PredicateType> inline
+typename SequenceType::size_type erase_if( SequenceType &seq,
+ PredicateType pred ) {
+ typename SequenceType::size_type erased = 0;
+ for ( typename SequenceType::iterator i = seq.begin(); i != seq.end(); ) {
+ if ( pred( *i ) ) {
+ i = seq.erase( i );
+ ++erased;
+ } else
+ ++i;
+ }
+ return erased;
+}
+
+/**
+ * Erases only the first element in the given sequence for which the given
+ * predicate is \c true.
*
* @tparam SequenceType The sequence type.
* @tparam PredicateType The predicate type.
=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp 2012-08-14 11:13:50 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp 2012-08-15 15:14:25 +0000
@@ -92,12 +92,12 @@
void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj)
{
- ar & obj.get_value();
+ ar & obj.value();
}
void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj)
{
- ar & obj.get_value();
+ ar & obj.value();
}
#endif
=== modified file 'src/zorbatypes/integer.h'
--- src/zorbatypes/integer.h 2012-08-14 11:13:50 +0000
+++ src/zorbatypes/integer.h 2012-08-15 15:14:25 +0000
@@ -32,11 +32,13 @@
#include "zstring.h"
#ifdef ZORBA_WITH_BIG_INTEGER
-# define TEMPLATE_DECL(I) /* nothing */
-# define INTEGER_IMPL(I) IntegerImpl
+# define TEMPLATE_DECL(I) /* nothing */
+# define INTEGER_IMPL(I) IntegerImpl
+# define TEMPLATE_TYPENAME /* nothing */
#else
-# define TEMPLATE_DECL(I) template<typename I> /* spacer */
-# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
+# define TEMPLATE_DECL(I) template<typename I> /* spacer */
+# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */
+# define TEMPLATE_TYPENAME typename
#endif /* ZORBA_WITH_BIG_INTEGER */
#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
@@ -58,6 +60,11 @@
class IntegerImpl
{
public:
+#ifdef ZORBA_WITH_BIG_INTEGER
+ typedef MAPM value_type;
+#else
+ typedef IntType value_type;
+#endif /* ZORBA_WITH_BIG_INTEGER */
////////// constructors /////////////////////////////////////////////////////
@@ -114,12 +121,6 @@
TEMPLATE_DECL(IntType2)
IntegerImpl( INTEGER_IMPL(IntType2) const &i );
- /////////////////////////////////////////////////////////////////////////////
-
- #ifndef ZORBA_WITH_BIG_INTEGER
- IntType& get_value() { return value_; }
- #endif
-
////////// assignment operators /////////////////////////////////////////////
/**
@@ -458,6 +459,8 @@
bool is_xs_unsignedShort() const;
int sign() const;
zstring toString() const;
+ value_type& value();
+ value_type const& value() const;
static IntegerImpl const& one();
static IntegerImpl const& zero();
@@ -465,10 +468,8 @@
private:
#ifdef ZORBA_WITH_BIG_INTEGER
- typedef MAPM value_type;
typedef long int_cast_type;
#else
- typedef IntType value_type;
typedef IntType int_cast_type;
#endif /* ZORBA_WITH_BIG_INTEGER */
@@ -1121,6 +1122,17 @@
#endif /* ZORBA_WITH_BIG_INTEGER */
+TEMPLATE_DECL(I) inline
+TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type& INTEGER_IMPL(I)::value() {
+ return value_;
+}
+
+TEMPLATE_DECL(I) inline
+TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type const&
+INTEGER_IMPL(I)::value() const {
+ return value_;
+}
+
TEMPLATE_DECL(I)
inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) {
return os << i.toString();
Follow ups