From 8cddd264e57ab89fc4c6952b2b390457a4bfbedf Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 7 Sep 2018 18:47:28 +0200 Subject: Fixes for C++17 mode Close #180 --- cpp/src/Ice/Reference.cpp | 70 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-) (limited to 'cpp/src/Ice/Reference.cpp') diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 1e7a9be8008..c54e62ab92d 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -65,14 +65,6 @@ public: Init init; -struct RandomNumberGenerator : public std::unary_function -{ - ptrdiff_t operator()(ptrdiff_t d) - { - return IceUtilInternal::random(static_cast(d)); - } -}; - } CommunicatorPtr @@ -507,6 +499,7 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } +#ifndef ICE_CPP11_COMPILER class ConnectionIsDatagram : public unary_function { public: @@ -528,6 +521,7 @@ public: return p->endpoint()->secure(); } }; +#endif IceInternal::Reference::Reference(const InstancePtr& instance, const CommunicatorPtr& communicator, @@ -1907,6 +1901,7 @@ IceInternal::RoutableReference::RoutableReference(const RoutableReference& r) : namespace { +#ifndef ICE_CPP11_COMPILER struct EndpointIsOpaque : public unary_function { public: @@ -1917,6 +1912,7 @@ public: return dynamic_cast(p.get()) != 0; } }; +#endif } @@ -1928,8 +1924,16 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE // // Filter out unknown endpoints. // +#ifdef ICE_CPP11_COMPILER + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return dynamic_cast(p.get()) != 0; + }), + endpoints.end()); +#else endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), EndpointIsOpaque()), endpoints.end()); - +#endif // // Filter out endpoints according to the mode of the reference. // @@ -1942,8 +1946,17 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE // // Filter out datagram endpoints. // +#ifdef ICE_CPP11_COMPILER + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return p->datagram(); + }), + endpoints.end()); +#else endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), Ice::constMemFun(&EndpointI::datagram)), endpoints.end()); +#endif break; } @@ -1953,9 +1966,18 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE // // Filter out non-datagram endpoints. // +#ifdef ICE_CPP11_COMPILER + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return !p->datagram(); + }), + endpoints.end()); +#else endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), not1(Ice::constMemFun(&EndpointI::datagram))), endpoints.end()); +#endif break; } } @@ -1967,8 +1989,7 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE { case ICE_ENUM(EndpointSelectionType, Random): { - RandomNumberGenerator rng; - random_shuffle(endpoints.begin(), endpoints.end(), rng); + IceUtilInternal::shuffle(endpoints.begin(), endpoints.end()); break; } case ICE_ENUM(EndpointSelectionType, Ordered): @@ -1992,8 +2013,17 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE DefaultsAndOverridesPtr overrides = getInstance()->defaultsAndOverrides(); if(overrides->overrideSecure ? overrides->overrideSecureValue : getSecure()) { +#ifdef ICE_CPP11_COMPILER + endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return !p->secure(); + }), + endpoints.end()); +#else endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), not1(Ice::constMemFun(&EndpointI::secure))), endpoints.end()); +#endif } else if(getPreferSecure()) { @@ -2002,7 +2032,15 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE // partition(), because otherwise some STL implementations // order our now randomized endpoints. // - stable_partition(endpoints.begin(), endpoints.end(), Ice::constMemFun(&EndpointI::secure)); +#ifdef ICE_CPP11_COMPILER + stable_partition(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return p->secure(); + }); +#else + stable_partition(endpoints.begin(), endpoints.end(), Ice::constMemFun(&EndpointI::secure)); +#endif } else { @@ -2011,7 +2049,15 @@ IceInternal::RoutableReference::filterEndpoints(const vector& allE // partition(), because otherwise some STL implementations // order our now randomized endpoints. // +#ifdef ICE_CPP11_COMPILER + stable_partition(endpoints.begin(), endpoints.end(), + [](const EndpointIPtr& p) + { + return !p->secure(); + }); +#else stable_partition(endpoints.begin(), endpoints.end(), not1(Ice::constMemFun(&EndpointI::secure))); +#endif } return endpoints; -- cgit v1.2.3