cxxomfort  rel.20210622
Simple backports for C++ - http://ryan.gulix.cl/fossil.cgi/cxxomfort/
Files
Base Features of cxxomfort

Files

file  alignof.hpp
 Implementation details for "alignof" emulation.
 
file  base/cstdint.hpp
 
file  explicit_cast.hpp
 Explicit cast, and explicit_cast conversion operator for C++03Interfaces defined in this header:
 
file  nullptr.hpp
 Implementation detaisl for "nullptr" backport.
 
file  static_assert.hpp
 Implementation details for "static_assert" backport.
 
file  base.hpp
 Minimal cxxomfort setup.For more complete cxxomfort setup (includes more headers, adds new names and functions), use one of these:
 

Detailed Description

The set of basic features of cxxomfort. These features are included automatically when #include <cxxomfort/base.hpp> or any of the cxxomfort headers are #include -d-.

Most of the features here involve setting up a common ground between C++03 and C++11; of particular interest is the backporting of the two keywords nullptr and static_assert .

nullptr - null pointer literal

cxxomfort includes among its facilities the "official" backport implementation for the special literal nullptr which represents a "null pointer constant".

nullptr can be used anywhere where a pointer could be initialized to a "null" value, replacing the usage of eg.: int * p = NULL or 0 in older code.

The Standard also provides the name std::nullptr_t for the type of the of the null pointer literal and can be used for overloading. Cxxomfort also provides this name dirctly.

See Also

static_assert - Compile time assertions

cxxomfort includes among its facilities a backport implementation for the "compile time assertions" feature: the C++11 keyword static_assert can be used to issue a check that is performed a compile time, resulting in an error message if the condition is not met.

Example usage:

// example static_assert
static_assert( is_same<typename std::string::value_type, char>::value, "string?");
// since it is a macro, tests that contain commas must be reformulated
static_assert((sizeof(pair<int,int>) > sizeof(int)), "pair?");
enum foo { ... };
enum { complicated_test =
is_same< typename underlying_type<foo>::type,
typename decay< map< int, vector<foo> >::value_type >::type
>::value
};
static_assert (complicated_test, "complicated?");

As a cxxomfort-specific extension, the macro static_assert0 is also provided that emulates C*+17's "short static_assert" feature:

static_assert ( test, "message" );
static_assert0 ( test ); // roughly equals static_assert ( test, "test" );

See static_assert for more details.

explicit_cast<To>

cxxomfort library automatically includes an implementation of Imperfect C++'s explicit_cast<> for use in types that need to enable explicit conversion in both C++11 (where explicit operator... is available) and C++03.

struct A {
...
};
struct B {
...
CXXO_EXPLICIT_OPERATOR(A) () const {
return A();
}
B b;
A a = explicit_cast<A>(b);
// equivalent to static_cast in C++>=11.

See explicit_cast for more information and this StackOverflow question for more rationale on implementation and mapping to C++11.

"Move" emulation

cxxomfort implements a simplified variant of Boost:Move aka "move semantics" in C++03.

Global Iterator Accessors

Global iterator accessors

cxxomfort provides backports for the global iterator accessors std::begin and std::end in C++11 which allow for uniform access of sequences and container objects.

array<int, 4> S1;
char S2[27];
vector<float> S3;
map<int,string> S4;
// for each of these, the following expression works replacing the object:
transform ( begin(S1), end(S1), begin(S1), somefunction );

For related features see: size() , move() , fixed_vector .

The global begin, end are documented at begin and end @ cppreference .

Inclusion Details

Except for this page all features should be explicitly included to the project by #include -ing the necessary header.