Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 3b0d81dd2661a8b4a3b99ad1a80338eeb3d81dfe130aaf82a2faac4ef1a674c6
Page Name:Features
Date: 2019-02-03 22:22:17
Original User: luismachuca
Parent: 0240dd03bb0a1e6cd4f115c68e1e26030c25722ec0ba4530641ffa17a83b5471 (diff)
Next 5959a3a26179503b06b6ca53edb68f9835f51058fb2e2fc3b3ecdfe3bcfc86fb
Content

The cxxomfort library adds various features that provide C++03, C++11 with partial support for features from later standards. For example, you can get some C++11 features in C++03, or C++14 features in C++11 (and sometimes even in C++03!).

The featureset described here is automatically included when using #include <cxxomfort/cxxomfort.hpp> or #include <cxxomfort/backports.hpp>, but you can get a more granular control of features by including specific headers. In particular, there's a .hpp header for each Standard C++ header that has backports in the library .

Base Features

This is the base feature set that is always included automatically when you use this library. Most of it involves backporting to C++03 some features from C++11. If access to only these base features is desired for more granular control, include as follows:

#include <cxxomfort/base.hpp>

The base feature set comprises:

nullptr / null pointer literal -- static_assert -- Iterator Helpers begin() and end() -- explicit_cast / explicit operator conversion emulation -- enable_if and conditional -- Movable type emulation -- Extended integral types

Standard Features

This is the "normal" feature set, which basically consists of backporting or integrating features from selected C++ headers. In order to access these one can explicitly invoke cxxomfort.hpp or backports.hpp, or any of the more specific headers with the backports wanted.

#include <cxxomfort/cxxomfort.hpp> // the entire library
#include <cxxomfort/backports.hpp> // C++ backports and minor assist only

Features from:

<algorithm> -- <array> -- <cstddef> -- <cstdint> -- <cuchar> -- <forward_list> -- <functional> -- <limits> -- <memory> -- <numeric> -- <random> -- <string> -- <string_view> -- <system_error> -- <tuple> -- <typeindex> -- <type traits> -- <utility>

Other Features

The library also adds some of its own assortment of features specific to cxxomfort - as in, not part of C++ revisions or proposals.

There's also utilities not included in the normal cxxomfort distribution, called Extras.

Details of Base Features

Here follows a listing of features.

Null pointer literal

Implemented by base.hpp.

C++11 defines a "null pointer literal" as a special keyword that can be used to explicitly indicate a null pointer and its type. This allows code relying on null pointers to implement null-specific features such as function overloads, as well as avoid ambiguities due to null-to-integral promotion. In C++11, this literal is named `nullptr` and is documented here, including usage examples.

This library implements the null pointer literal in C++03 in the way recommended by the Standard (see also Meyer's implementation).

Known limitations:

  • Requires the inclusion of a header to be used.
  • Does not implement any operators beyond implicit conversion.

Static Assert

Implements: n1604, n1720 for compile-time assertions into the language.

Implemented by base.hpp.

C++11 adds the capability to perform assertions at compile time via a special keyword. This allows code to test for prerequisites at compile-time and deliver better error messages.

The compile-time assertion feature in C++11 is documented here, including usage samples.

The static_assert keyword is implemented in C++03 as a pseudo-keyword using a macro with the same syntax; however, being a macro, it has some limitations.

Known limitations:

  • Can not take arguments containing comas - for those, wrapping parentheses, a typedef or an enum declaration are required (and recommended even in C++11 mode, as they make code clearer).
  • The compiler won't be able to display the actual error message string, although it will at least point to its location (which, when using an IDE, should amount to the same effect).

Non-backport assists:

  • Starting in version 0.42): the extra pseudokeyword static_assert0 serves as a static assert without message, as per C++17/C++20.

Metaprogramming Helpers

Implementation of the helpers identity, enable_if, conditional.

Brief description:

template <typename T> struct identity {
    typedef T type;
};
template <bool If, typename T> struct enable_if {
    defined_if(If) typedef T type;
};
template <bool If, typename A, typename B> struct conditional {
    defined_if(If) typedef A type;
    defined_else() typedef B type;
};

The three are unconditionally added to namespace std.


Iterator Access Functions

Implemented by base.hpp. See also: https://en.cppreference.com/w/cpp/iterator .

The following interfaces are backported from C++11:

  • std::begin and std::end -- generically find the begin and end iterators for a container-like expression.
  • std::next and std::prev -- generically advance an iterator in forward or backward direction.