View Full Version : [ClanLib 3] Variadic template replacement

07-12-2013, 01:40 AM
I converted the callbacks, signals and the NetGameDispatcher to use variadic templates introduced in C++11. Visual C++ 2012 should support this to some extent via faux variadic templates.

Callbacks do not work with GCC 4.8.1 (but they work on clang). This also affects NetGameDispatcher since it uses Callbacks. GCC will throw an error whenever you call Callback::set().
Update: Adding spaces in between seems to fix the error.

Files affected:
API/Core/Signals/signal.h (replace signal_v#.h)
API/Core/Signals/callback.h (replace callback_[v]#.h)
variadic_test.cpp (does not test event_dispatcher)

07-12-2013, 09:11 AM
http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx "C++11 Features (Modern C++)"

Variadic templates v0.9, v1.0

Visual Studio 2010 = No
Visual Studio 2012 = No

Haven't tested it though

07-19-2013, 11:22 PM
C++11 provide std::functions (and std::bind) that can store lambda, functors, methods, and callbacks. The implementation of std::function rely on variadic templates. If C++11 was supported by VC++, I think it may be really cool to use std::functions. But it seams VC++ compiler won't support variadic templates until a long time (the team developing VC's stl implementation seams to be complaining about the absence of variadic templates and the need to emulate them, where they can, throught macros). So your patch won't probably compile with VC's compiler.

07-21-2013, 10:45 AM
I made a mistake. VS2012 does not support variadic templates, but VS2012 November CTP does support it via library emulation. VS2013 Preview was released with actual support with variadic templates (http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx). I have just tested the code and it compiles fine there.

The only problem with this patch is that we would have to drop support for VS08, 10 and 12.