summaryrefslogtreecommitdiff
path: root/cpp/include
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-09-07 18:47:28 +0200
committerJose <jose@zeroc.com>2018-09-07 18:47:28 +0200
commit8cddd264e57ab89fc4c6952b2b390457a4bfbedf (patch)
tree66bb34aa13289ed0017a9460e800740516bb1278 /cpp/include
parentEnable test workers for PHP, Ruby and Python (diff)
downloadice-8cddd264e57ab89fc4c6952b2b390457a4bfbedf.tar.bz2
ice-8cddd264e57ab89fc4c6952b2b390457a4bfbedf.tar.xz
ice-8cddd264e57ab89fc4c6952b2b390457a4bfbedf.zip
Fixes for C++17 mode
Close #180
Diffstat (limited to 'cpp/include')
-rw-r--r--cpp/include/Ice/Functional.h2
-rw-r--r--cpp/include/Ice/MetricsObserverI.h14
-rw-r--r--cpp/include/IceUtil/Functional.h4
-rw-r--r--cpp/include/IceUtil/Random.h34
4 files changed, 53 insertions, 1 deletions
diff --git a/cpp/include/Ice/Functional.h b/cpp/include/Ice/Functional.h
index 96f1d2d24e9..bf4cfeb50b3 100644
--- a/cpp/include/Ice/Functional.h
+++ b/cpp/include/Ice/Functional.h
@@ -10,7 +10,7 @@
#ifndef ICE_FUNCTIONAL_H
#define ICE_FUNCTIONAL_H
-# if !defined(ICE_CPP11_MAPPING) || defined(ICE_BUILDING_SRC)
+#ifndef ICE_CPP11_MAPPING
#include <IceUtil/Functional.h>
#include <Ice/Handle.h>
diff --git a/cpp/include/Ice/MetricsObserverI.h b/cpp/include/Ice/MetricsObserverI.h
index d5848d2f4ae..a360be048ee 100644
--- a/cpp/include/Ice/MetricsObserverI.h
+++ b/cpp/include/Ice/MetricsObserverI.h
@@ -132,6 +132,20 @@ protected:
memberFn)));
}
+#if ICE_CPLUSPLUS >= 201703L
+ //
+ // Since C++17 the noexcept-specification is part of the function type and we need a separate
+ // overload to handle memberFn being noexcept
+ //
+ template<typename I, typename O, typename Y> void
+ add(const std::string& name, O (Helper::*getFn)() const, Y (I::*memberFn)() const noexcept)
+ {
+ _attributes.insert(typename std::map<std::string,
+ Resolver*>::value_type(name, new MemberFunctionResolver<I, O, Y>(name, getFn,
+ memberFn)));
+ }
+#endif
+
private:
template<typename Y> class HelperMemberResolver : public Resolver
diff --git a/cpp/include/IceUtil/Functional.h b/cpp/include/IceUtil/Functional.h
index 9f0db18104e..f370d0099a3 100644
--- a/cpp/include/IceUtil/Functional.h
+++ b/cpp/include/IceUtil/Functional.h
@@ -10,6 +10,8 @@
#ifndef ICE_UTIL_FUNCTIONAL_H
#define ICE_UTIL_FUNCTIONAL_H
+#ifndef ICE_CPP11_MAPPING
+
#include <IceUtil/Handle.h>
#include <functional>
@@ -386,3 +388,5 @@ secondConstVoidMemFun1(void (T::*p)(A) const)
}
#endif
+
+#endif
diff --git a/cpp/include/IceUtil/Random.h b/cpp/include/IceUtil/Random.h
index f576205d201..69d4c0b4dea 100644
--- a/cpp/include/IceUtil/Random.h
+++ b/cpp/include/IceUtil/Random.h
@@ -13,12 +13,46 @@
#include <IceUtil/Config.h>
#include <IceUtil/Exception.h>
+#ifdef ICE_CPP11_COMPILER
+# include <algorithm>
+# include <random>
+#endif
+
namespace IceUtilInternal
{
ICE_API void generateRandom(char*, size_t);
ICE_API unsigned int random(int = 0);
+#ifdef ICE_CPP11_COMPILER
+
+template<class T>
+void shuffle(T first, T last)
+{
+ std::random_device rd;
+ std::mt19937 rng(rd());
+ std::shuffle(first, last, rng);
+}
+
+#else
+
+struct RandomNumberGenerator : public std::unary_function<std::ptrdiff_t, std::ptrdiff_t>
+{
+ std::ptrdiff_t operator()(std::ptrdiff_t d)
+ {
+ return IceUtilInternal::random(static_cast<int>(d));
+ }
+};
+
+template<class T>
+void shuffle(T first, T last)
+{
+ RandomNumberGenerator rng;
+ random_shuffle(first, last, rng);
+}
+
+#endif
+
}
#endif