From 443300ddc77a39634ce30e092963db3677d35b72 Mon Sep 17 00:00:00 2001 From: "Michael X. Grey" Date: Thu, 1 Feb 2018 09:46:13 -0600 Subject: [PATCH] Use template specialization to sidestep complaints from clang (#963) --- dart/common/detail/CompositeData.hpp | 31 +++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/dart/common/detail/CompositeData.hpp b/dart/common/detail/CompositeData.hpp index 2a08d62307728..1805d086331fd 100644 --- a/dart/common/detail/CompositeData.hpp +++ b/dart/common/detail/CompositeData.hpp @@ -47,13 +47,38 @@ namespace dart { namespace common { namespace detail { +//============================================================================== +// This default template definition will be called when AspectOrComposite is +// an Aspect. +template +struct GetAspectImpl +{ + using Type = AspectOrComposite; +}; + +//============================================================================== +// This template specialization will be called when AspectOrComposite is not +// an Aspect (and is presumably a composite that defines a nested Aspect type). +template +struct GetAspectImpl +{ + // If you get a compiler error that leads you here, then you are trying to + // ask for the Aspect of an object that is not associated with any Aspect. + // That means it does not define a nested Aspect type (such as how + // RevoluteJoint defines the RevoluteJoint::Aspect). + // + // Whatever function is leading to the error must be given a template type + // that either defines a nested type with the name Aspect, or else inherits + // from the type dart::common::Aspect. + using Type = typename AspectOrComposite::Aspect; +}; + //============================================================================== template struct GetAspect { - using Type = typename std::conditional< - std::is_base_of::value, - AspectT, typename AspectT::Aspect>::type; + using Type = typename GetAspectImpl< + AspectT, std::is_base_of::value>::Type; }; //==============================================================================