Hi.
I,m working on a skech with a variadic data structure. I have 2 static function specialization getHelper, to get data out of the variadic.
I want to put those 2 static function into a namespace to limit there scope. It work well on UNO, but it did not compile on DUE:
error specialization of 'template<unsigned int idx, class T> struct InterfaceHelper::GetHelper' in different namespace
When outside a namespace, the two board compile...
tried couple of other board in the IDE list, the DUE seems to be the only one that not compiling...
Thanks.
template <typename T>
class InterfaceObj {
public:
InterfaceObj(const char* key) : _key(key) { };
const char* _key;
T value;
InterfaceObj<T> operator=(T _value) { value = _value; };
T operator()(){ return value;};
char* getKey() const { return _key; };
};
namespace InterfaceHelper {
template<size_t idx, typename T>
struct GetHelper;
//template<size_t idx, typename T>
//struct SetHelper;
};
template<typename ... T>
struct Interface
{
};
template<typename T, typename ... Rest>
struct Interface<T, Rest ...>
{
Interface(const InterfaceObj<T> first, const InterfaceObj<Rest> ... rest)
: first(first) //-&
, rest(rest...) //-
{}
InterfaceObj<T> first; //-*
Interface<Rest ... > rest; //-*
template<size_t idx>
auto get() -> decltype(InterfaceHelper::GetHelper<idx, Interface<T,Rest...>>::get(*this))
{
return InterfaceHelper::GetHelper<idx, Interface<T,Rest...>>::get(*this);
}
template<size_t idx>
void set(T data)
{
auto id = *(InterfaceHelper::GetHelper<idx, Interface<T,Rest...>>::get(*this));
id->_value = data;
}
template<size_t idx>
auto getPtr() -> decltype(*InterfaceHelper::GetHelper<idx, Interface<T,Rest...>>::get(*this))
{
return *InterfaceHelper::GetHelper<idx, Interface<T,Rest...>>::get(*this);
}
};
template<typename T, typename ... Rest>
struct InterfaceHelper::GetHelper<0, Interface<T, Rest ... >> {
static InterfaceObj<T> get(Interface<T, Rest...>& data) // <T>* --> <T> et & data
{
return data.first;
}
};
template<size_t idx, typename T, typename ... Rest>
struct InterfaceHelper::GetHelper<idx, Interface<T, Rest ... >> {
static auto get(Interface<T, Rest...>& data) -> decltype(GetHelper<idx-1, Interface<Rest ...>>::get(data.rest))
{
return GetHelper<idx-1, Interface<Rest ...>>::get(data.rest);
}
};