From 1811a870b7f10b5c58faae2848186f07bdbde6d8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 21 Mar 2018 20:27:14 +0000 Subject: Simplify typeRead/typeWrite by replacing enable_if with if constexpr --- slicer/slicer/modelPartsTypes.impl.h | 93 ++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index a2f2c62..149bb1d 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -56,81 +56,68 @@ namespace Slicer { return ModelObject && mp->HasValue(); } -#define IfLocal(T) \ - typename std::enable_if::value>::type -#define IfNotLocal(T) \ - typename std::enable_if::value>::type - template - IfNotLocal(T) + void typeWrite(::Ice::OutputStreamPtr & s, const ::IceUtil::Optional & m) { - typedef Ice::StreamableTraits traits; - typedef Ice::StreamOptionalHelper SOH; - s->startEncapsulation(); - if (m && s->writeOptional(0, SOH::optionalFormat)) { - SOH::write(s.get(), *m); + if constexpr (!Slicer::isLocal::value) { + typedef Ice::StreamableTraits traits; + typedef Ice::StreamOptionalHelper SOH; + s->startEncapsulation(); + if (m && s->writeOptional(0, SOH::optionalFormat)) { + SOH::write(s.get(), *m); + } + s->endEncapsulation(); + } + else { + throw LocalTypeException(); } - s->endEncapsulation(); - } - - template - IfLocal(T) - typeWrite(::Ice::OutputStreamPtr &, const ::IceUtil::Optional &) - { - throw LocalTypeException(); } template - IfNotLocal(T) + void typeWrite(::Ice::OutputStreamPtr & s, const T & m) { - s->write(m); - } - - template - IfLocal(T) - typeWrite(::Ice::OutputStreamPtr &, const T &) - { - throw LocalTypeException(); + if constexpr (!Slicer::isLocal::value) { + s->write(m); + } + else { + throw LocalTypeException(); + } } template - IfNotLocal(T) + void typeRead(::Ice::InputStreamPtr & s, ::IceUtil::Optional & m) { - typedef Ice::StreamableTraits traits; - typedef Ice::StreamOptionalHelper SOH; - s->startEncapsulation(); - if (s->readOptional(0, SOH::optionalFormat)) { - m.__setIsSet(); - SOH::read(s.get(), *m); + if constexpr (!Slicer::isLocal::value) { + typedef Ice::StreamableTraits traits; + typedef Ice::StreamOptionalHelper SOH; + s->startEncapsulation(); + if (s->readOptional(0, SOH::optionalFormat)) { + m.__setIsSet(); + SOH::read(s.get(), *m); + } + else { + m = IceUtil::None; + } + s->endEncapsulation(); } else { - m = IceUtil::None; + throw LocalTypeException(); } - s->endEncapsulation(); - } - - template - IfLocal(T) - typeRead(::Ice::InputStreamPtr &, ::IceUtil::Optional &) - { - throw LocalTypeException(); } template - IfNotLocal(T) + void typeRead(::Ice::InputStreamPtr & s, T & m) { - s->read(m); - } - - template - IfLocal(T) - typeRead(::Ice::InputStreamPtr &, T &) - { - throw LocalTypeException(); + if constexpr (!Slicer::isLocal::value) { + s->read(m); + } + else { + throw LocalTypeException(); + } } template -- cgit v1.2.3