Reputation: 28659
I have the following little test application, where I'm trying to employ a template using declaration.
However, it doesn't compile. (I'm using gcc 4.6.1)
src/main.cpp:36:3: error: expected unqualified-id before ‘using’
Any insight greatly appreciated!
#include <iostream>
#include <utility>
template<typename F, typename... Args>
struct invoke;
// specialisation of invoke for 1 parameter
template<typename F, typename A0>
struct invoke<F, A0>
{
invoke(F& f_, A0&& a0_)
: _f(f_)
, _a0(std::move(a0_))
{}
void operator()()
{
_f(_a0);
}
F _f;
A0 _a0;
};
template<typename F>
struct traits;
// fwd declaration for handler
struct handler;
// specialisation of traits for handler
template<>
struct traits<handler>
{
template<class F, typename... Args>
using call_t = invoke<F, Args...>; // line 36
};
template<typename F>
struct do_it
{
template<typename... Args>
void operator()(F& _f, Args... args)
{
// create an object of the type declared in traits, and call it
typename traits<F>::template call_t<F, Args...> func(_f, std::forward<Args>(args)...);
func();
}
};
struct handler
{
void operator()(int i)
{
std::cout << i << std::endl;
}
};
int main()
{
handler h;
do_it<handler> d;
d(h, 4);
return 0;
}
Upvotes: 2
Views: 2326
Reputation: 53047
According to this: http://wiki.apache.org/stdcxx/C++0xCompilerSupport and this: http://gcc.gnu.org/projects/cxx0x.html
Template aliases aren't in GCC 4.6\ There should be a patch which fixes it.
(I may be mistaken that you're using template aliases and so this might not apply to you. I'm not very familiar with C++11)
Upvotes: 3