diff options
Diffstat (limited to 'gcc-4.9/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template4.C')
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template4.C | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template4.C b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template4.C new file mode 100644 index 0000000..a65727a --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template4.C @@ -0,0 +1,42 @@ +// PR c++/51459 +// { dg-do run { target c++11 } } + +struct func { + virtual ~func() { } + virtual void operator()() const = 0; + virtual func* clone() const = 0; +}; + +template<typename T> +struct funcimpl : func { + explicit funcimpl(T t) : t(t) { } + void operator()() const { t(); } + func* clone() const { return new funcimpl(*this); } + T t; +}; + +struct function +{ + func* p; + + template<typename T> + function(T t) : p(new funcimpl<T>(t)) { } + + ~function() { delete p; } + + function(const function& f) : p(f.p->clone()) { } + + function& operator=(const function& ) = delete; + + void operator()() const { (*p)(); } +}; + +template <typename F> +function animate(F f) { return [=]{ f(); }; } + +int main() +{ + function linear1 = []{}; + function av(animate(linear1)); + av(); +} |