c++-gtk-utils
|
The 1.2 and 2.0 series of c++-gtk-utils
The 2.0 series of c++-gtk-utils is only compilable in C++0x/11. Because of this, the 1.2 series is not at an end nor deprecated: it will be some time before it can be assumed that all programs will be written to use only C++0x/11, or that all generally installed compilers will support C++0x/11. Therefore, if new features are added to c++-gtk-utils, it is intended that they will be added to both branches at the same time.
However, some features have more flexible usage in the 2.0 series than in the 1.2 series, because of the availability of variadic templates and generalised function objects, and in certain circumstances they can be more efficiently implemented because of the availability of r-value references.
The main difference experienced by those writing code against the 2.0 series rather than the 1.2 series, is that in the 2.0 series the TypeTuple struct is no longer used to provide more than one unbound argument of callback, functor and emitter objects. This means that, say, Cgu::CallbackArg<TypeTuple<int, int, int> > in the 1.2 series just becomes Cgu::CallbackArg<int, int, int> in the 2.0 series.
The differences between the series are explained in more detail below. The 2.0 series of the library defines the symbol CGU_API_VERSION with the value 20 in the header file c++-gtk-utils/cgu_config.h, which can be used for conditional compilation purposes where it is intended that user code should be compilable against both series.
Compatibility
The c++-gtk-utils-1.2 series is compilable in both C++98/03 and C++0x/11. The c++-gtk-utils-2.0 series however is only compilable in C++0x/11: it uses amongst other things variadic templates to extend the usefulness of callback objects, and some other features only available in C++0x/11, such as r-value references, and replaces std::auto_ptr smart pointers by std::unique_ptr.
c++-gtk-utils-2.0 is mainly API compatible with c++-gtk-utils-1.2. The main aspects of user code which may need to be changed to use the 2.0 series relate to:
(a) Callback::Callback is now typedef'ed to Callback::CallbackArg<> instead of Callback::CallbackArg<void>, and similarly the typedefs of Callback::Functor, Callback::SafeFunctor and Emitter. However, assuming that users have always used Callback, Emitter, etc instead of CallbackArg<void>, EmitterArg<void> and so forth, then this change will not be noticed.
(b) A TypeTuple struct is no longer used to provide more than one unbound argument. This means that, say, Cgu::CallbackArg<TypeTuple<int, int, int> > in the 1.2 series just becomes Cgu::CallbackArg<int, int, int> in the 2.0 series.
(c) The Cgu::DoIf::mem_fun() and Cgu::DoIf::fun() conditional compilation functions can now represent functions taking any number of arguments. This means that where the referenced functions are overloaded, explicit disambiguation is required in all cases (it is no longer possible to avoid disambiguation where the number of arguments are different).
Enhancements
The main enhancements with the 2.0 series are that:
Usage note: use the normal non- std::function based callback objects if they suit the circumstances, as they are more efficient. The libstdc++ libraries which have been tested, when constructing function objects with std::function and std::bind, copy bound arguments four times on construction and two more times on dispatch, unless they have a r-value constructor, in which case they are copied twice and once respectively with two and one additional calls to the r-value constructor.
Configuration
It should be noted that the pkg-config files offered by c++-gtk-utils have changed their format. Version 1.2 provided c++-gtk-utils-1.2.pc when compiled against GTK+2, and c++-gtk-utils-1.3.pc when compiled against GTK+3, which looking back on it was somewhat odd numbering. The 2.0 series offers c++-gtk-utils-2-2.0.pc when compiled against GTK+2, and c++-gtk-utils-3-2.0.pc when compiled against GTK+3.
The 2.0 series is parallel-installable with the 1.2 series. User code can be set up to use different library versions using the pkg-config files mentioned above. The versions compiled against GTK+2 are also parallel-installable with the versions compiled against GTK+3, so at any one time a user may have four versions installed and individually usable, namely 1.2 for GTK+2, 1.2 for GTK+3, 2.0 for GTK+2 and 2.0 for GTK+3.