Hello,
I have a chain of classes with a pair of templated set/get methods that require different return semantics based on the type.
float pod = GetAttribute<float>(0);
SomeClass* pObject = GetAttribute<SomeClass>(1);
std::vector<float>& vPOD = GetAttributeArray<float>(2);
const std::vector<SomeClass*>& vObjects= GetAttributeArray<SomeClass>(2);
auto & decltype seemed to do the job:
template<typename Type>
auto Variable::GetValue(void) const -> decltype(returnSemantics<Type>::value)
{
ACL_ASSERT(m_type == getVariableType<Type>::type);
ACL_ASSERT(m_isArray == isArray<Type>::value);
return getObjectData<Type, isPrimitiveType<Type>::value>::GetData(m_pData, m_objectType);
}
returnSemantics is a templated struct that gets specialized for the destired return type:
template<typename Type, bool isPOD = isPrimitiveType<Type>::value>
struct returnSemantics
{
static Type value = Type();
};
template<typename Type>
struct returnSemantics<Type, true>
{
static Type value;
};
template<typename Type>
Type returnSemantics<Type, true>::value = Type();
template<typename Type>
struct returnSemantics<Type, false>
{
static Type* value;
};
template<typename Type>
Type* returnSemantics<Type, false>::value = nullptr;
However, I can't seem to get this to work with the "array"-overload of the method:
template<typename Type>
auto AttributeComponent::GetAttributeArray(unsigned int slot) -> decltype(core::returnSemantics<std::vector<Type>>::value)
{
return GetAttribute<std::vector<Type>>(slot);
}
When I use this code like in the examples above, I get:
error C2893: Funktionsvorlage 'unknown-type acl::event::AttributeComponent::GetAttributeArray(unsigned int)' konnte nicht spezialisiert werden
1> Mit den folgenden Vorlagenargumenten:
1> 'Type=int'
which translates to something along the lines of "function template '...' could not be specialized with template arguments 'Type=int'. Why? Is there anything wrong with the decltype-usage?
decltype(core::returnSemantics<std::vector<Type>>::value)
I'm using the "Type" argument to form a vector, and use the vector as template-argument for my returnSemantics-structure... I'm using Visual Studio 2013, does anybode see the issue here?
EDIT: Also fails without the specific overload, even using
std::vector<float>& vTest = GetAttribute<std::vector<float>>(0);
which calls the first posted method fails with the same compilation error...