New features in the GCC versions 4.3 and 4.4
New Builder
Recent versions of the GNU compiler include new features from the next C++ standard.
The new C++ standard, which is informally known as C++0x, is still in the process of being hashed out, but many features of the next generation C++ have already made their way into the GNU compiler (GCC) versions 4.3 and 4.4. You can enable these features by entering the -std=c++0x option.
Many of these new features are mature enough to use without worries. Users of the influential Boost libraries [1] will be familiar with most of the changes because a fair share of the new standard is based on Boost. The technical details are available in the draft version of the C++ standard [2] and in the "Draft Technical Report on C++ Library Extensions" (TR1) [3]. Read on for a look at some of the most important changes in recent versions of GCC.
New Functions
The C99 standard substantially raised the number of mathematical functions available. It stands to reason that all of these C functions should be available in C++. The cmath library under the new C++ standard incorporates the full set of C99 functions (Table 1), while defining many additional mathematical functions (Table 2). The new C++ standard also mandates that new C libraries, such as stdint.h (fixed-size integers) or fenv.h (direct access to the floating point unit), must be available in C++. The C++ names for these libraries are cstdint, cfenv, and so on. The definitions are all bundled in the std namespace.
New Containers
Several new containers also inhabit the new standard, starting with the hash-based variants of the associative containers set, multiset, and map. These containers were originally planned for the older standard, but the developers dropped them for want of time. The new standard includes the unordered_set and unordered_map libraries, which define the hash-based containers unordered_set, unordered_multiset, and unordered_map. The unordered name component indicates that a comparative operator is not needed in order to use these containers. The unordered_set class definition is as follows:
template<class Value, class Hash=hash<Value>, class Pred=std::equal_to<Value>, class Alloc=std::allocator<Value> > class unorderd_set { ... }
With the template parameters, you can select the allocator (as with any standard container), specify the comparative predicate (this defaults to ==), and specify the hash function. If no specific information concerning the data is available, the default settings are a useful choice. Hash-based containers are faster than their tree-based counterparts (Table 3). The array (a lightweight class for a C array) and forward_list (a singly linked list) classes are also new.
Intelligent Pointers
The current C++ standard includes auto_ptr, a pointer that deletes an object automatically when it loses its value. The auto_ptr class has many restrictions. Each object can have only one owner, and strange things can happen in copying operations. More specifically, you cannot store an auto_ptr in a standard container. Effectively, auto_ptr causes more problems than it solves. The new C++ standard gets rid of auto_ptr and introduces improved, intelligent pointers. The new intelligent pointers are:
- unique_ptr, which is most similar to the legacy auto_ptr. The object belongs exclusively to the pointer. unique_ptr gives programmers an exception-proof approach to storing a pointer in a function.
- shared_ptr is a universally deployable, intelligent pointer. Multiple shared_ptr can share an object. If the programmer deletes the last shared_ptr pointing to an object, the destructor for the pointer calls the destructor for the object.
- weak_ptr monitors the objects managed by shared_ptr. The weak_ptr has no rights for the object. Thus, it is up to the programmer to ensure that the object stays alive while the pointer is alive. The weak_ptr and the shared_ptr are identical to the intelligent pointers of the Boost libraries.
The intelligent pointer collection should lead to more efficient programming as developers learn the nuances of the various new options.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4