D 2017-12-24T21:13:11.360 L Features P 11696d2e92168dcd3e049da5a430600887c069d4 U luismachuca W 22126 The cxxomfort library adds various features that provide C++03, C++11 with partial support for various features from later standards. For example, you can get some C++11 features in C++03, or C++1y features in C++11 (and sometimes even in C++03!). There is a specific featureset that is always included by default, but you can get a specific subset of features by including specific headers.
cxxomfort/cxxomfort.hpp
, most of them backlifted from C++11 to C++03:
* [Features/IntegratedTypeTraits|Integrated Type Traits] for inspection of native types.
* [Features/Keywords|List of C++11 keywords added by this library].
#include
)
* [#cxxo-nullptr|nullptr
] aka null pointer literal.
* [#cxxo-static_assert|static_assert
], compile-time assertions.
* [#cxxo-iterator|Iterator Helpers] such as global begin, end.
* [Features/explicit_cast|explicit_cast
] / explicit operator conversion backports.
* [Features/MetaprogrammingHelpers|Metaprogramming Helpers] such as enable_if.
* [Features/rvref|Rvalue references, move and forward] emulation.
* [Features/integrals|Extended integral types], aka uint16_t etc.
#include
, which also includes the above)
* [Features/SequencesInitialization|Initialization of Sequences and Containers]
* [#cxxo-algorithm|Features from std::forward_list
.
* [#cxxo-functional|Features from alignof
and very especially "[#cxxo-unique_ptr|unique_ptr]
" for dynamic management of objects.
* [#cxxo-random|Features from to_string
.
* [#cxxo-tuple|Features from ::cxxomfort
. To improve portability, then the features that are present in namespace ::std
in the new standard are added there via a using
directive.
The library also implements some of the new [Features/Keywords|keywords added in C++11], in particular static_assert
.
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 [http://en.cppreference.com/w/cpp/language/nullptr|documented here], including usage examples.
This library implements the null pointer literal in C++03 in the way recommended by the Standard (see also [http://en.wikibooks.org/wiki/More_C++_Idioms/nullptr#Solution_and_Sample_Code|Meyer's implementation]).
When enabled, the macro CXXOMFORT_USING_nullptr
is defined.
Known limitations:
* Requires the inclusion of a header to be used.
* Does not implement any operators beyond implicit conversion.
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 [http://en.cppreference.com/w/cpp/language/static_assert|documented here], including usage samples.
The static_assert
keyword is implemented here as a pseudo-keyword using a macro with the same syntax; however, being a macro, it has some limitations.
(Starting in version 0.42
) The extra pseudokeyword static_assert0
.
When enabled, the macro CXXOMFORT_USING_static_assert
is defined.
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).
iterator.hpp
.
This library adds for C++03 the following global functions present in 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.
This library adds for C++03 and C++11 the following proposed global functions present in C++14:
* std::cbegin
-- generically return const_iterator with the same semantics as begin's.
* std::cend
-- generically return const_iterator with the same semantics as end's.
Each of the std::valarray
, which is container-like but does not define iterator types.
Finally, starting with version 0.45, the library also adds for all C++ modes the following proposed global functions present in N4017 (non-member container accessor functions):
* cxxomfort::size
-- generically return container size.
#include
the cxxomfort/algorithms.hpp header (yes, the plural is part of the name). Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
The library includes some C++11, C++14 and C++17 algorithms backported to previous standard versions:
* The uninitialized_copy_n
function.
* The "copy_if", "copy_n" and "partition_copy" algorithms. ([http://en.cppreference.com/w/cpp/algorithm/copy|External Documentation])
* The "[http://en.cppreference.com/w/cpp/algorithm/minmax|minmax]" and "[http://en.cppreference.com/w/cpp/algorithm/minmax_element|minmax_element]" algorithms. (External links)
* The "all_of", "any_of", "none_of" algorithms. ([http://en.cppreference.com/w/cpp/algorithm/all_any_none_of|External documentation])
* The new C++11 The "is_sorted" algorithm.
* The new C++11 "is_permutation" algorithm.
* The new C++14 overloads for equal
algorithm, specific to different-sized sequences.
* The new C++17 clamp
algorithm. ([http://en.cppreference.com/w/cpp/algorithm/clamp|External Documentation])
Example usage:
#include
the cxxomfort/cstddef.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
As a convenience for portability, the [Transparent Headers|
header:
* nullptr_t
from C++11 (see nullptr above).
* std::max_align_t
from C++11.
* std::byte
from C++17 (see [http://en.cppreference.com/w/cpp/types/byte|std::byte at cppreference] and [Features/std::byte] for more information).
#include
the cxxomfort/cstdint.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
As a convenience for portability, the [Transparent Headers|uint16_t, int64_t
, etc.
#include
the cxxomfort/forward_list.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
As a convenience for portability, the [Transparent Headers|forward_list
behaves much like a std::list
, except elements are only singly linked - thus, traversal is only possible in one direction, from begin to end.
Header Synopsis:
(pending)
The implementation is fairly incomplete as of yet, and it has some differences from the standard's provided one as I found it to be faulty.
* push_back
and emplace_back
members are provided.
* size
member is provided.
* insert
member taking a iterator range is provided.
* before_begin
is not provided as of yet.
* remove,remove_if
are unimplemented as of yet.
* erase_after
is unimplemented as of yet.
* unique
is unimplemented as of yet.
* reverse,resize
are unimplemented as of yet.
The [Transparent Headers|transparent header]
is also provided so that code can be written in a forwards-compatible manner using a standard #include directive. See the page for details.
#include
the cxxomfort/functional.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
The library includes some C++14 backported to previous standard versions:
* [Features/TransparentFunctors|Type-transparent functors] such as improved "bit_and" and "plus" (from [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3421.htm|n3421]), aka: their
specializations.
The library also provides the following functionality for incomplete TR1 implementations:
* The standard family of bit_and
, bir_or
and bit_xor
functors.
Example usage:
#include
the cxxomfort/iterator.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
The header simply redirects to the base.hpp headers, as the iterator-related features form part of the base cxxomfort package. See [[#base-iterator|Iterator Helpers]] for more details.
#include
the cxxomfort/limits.hpp header, which is not aggregated automatically.
The library includes a special template integral_limits
that extends std::numeric_limits
for integral types by adding const min, max members rather than functions, so that the values can be accessed generically from C++03.
For a given integral type integral, the type cxxomfort::integral_limits<integral>
inherits from std::numeric_limits
, and adds the following member values:
integral_limits::const_min
is equal to USHRT_MIN
(which should be zero).
The const_min,const_max
member variable has the same value as what is returned by the min(),max()
member functions.
The digits_base
member template, instantiated with an integer value, defines value
as a member with the number of digits the type takes in the given base, similar to digits,digits10
.
#include
the cxxomfort/memory.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
The library includes some features that are available via the
header for the management of pointers and memory:
* The C++11 addressof
function.
* A "alignof(T)
" macro that uses compiler specific to backport alignof
keyword (in C++03 compilers, usually something like __alignof
).
* A "alignas
" macro that uses compiler specifics to backport alignas
keyword.
* A partial implementation of C++11's aligned_storage
, depending on the two above features.
* A barebones implementation of pointer_traits
and of allocator_traits
to ease uniform API usage when writing eg.: containers.
* A backport of unique_ptr
for C++03, explained in its own section below.
The library implements alignof(type)
by calling a compiler-specific feature, usually something like __alignof(type)
. For alignas(size)
, only implemented in GCC for the moment, __attribute__
s are used.
The implementation of aligned_storage
is made compiler specific and either takes advantage of a compiler-defined intrinsic (in the case of GCC, MSVC) or aligns objects to the alignment of at most the largest known alignable native member (such as long double
or a member function pointer).
unique_ptr
"Unique" Smart Pointerunique_ptr.hpp
.
When using C++03 mode, this library implements the "unique_ptr" emulation created by Howard Hinnant. Once made available, the macro CXXOMFORT_USING_unique_ptr
is defined.
[http://en.cppreference.com/w/cpp/memory/unique_ptr|Documentation on unique_ptr] (external link). It is recommended to check this documentation as it provides both example usage and the rationale for usage cases.
#include
the cxxomfort/random.hpp header. Or just include cxxomfort/cxxomfort.hpp and it will be added automatically.
As a convenience for portability, the [Transparent Headers|
that changed name in C++11 onward, for example std::tr1::uniform_int_distribution
for std::tr1::uniform_int
.
#include
the cxxomfort/string.hpp header, which is not aggregated automatically.
The following interfaces from C++11 are defined and backported to C++03 by this header:
* The to_string
function template, which allows constructing a string from eg.: a native type, such as a long
numerical expression.
Example code:
#include
the cxxomfort/tuple.hpp header, which is not aggregated automatically.
The following interfaces from C++14 are defined and backported to C++03 and C++11 by this header:
* get(tuple)
- get a tuple's element by type (see: for an example).
* apply(function,tuple)
- apply a functioid to all elements of a tuple (see: [http://en.cppreference.com/w/cpp/utility/apply|cppreference documentation]).
* make_from_tuple
from C++17 - create an object using a tuple as constructor arguments (see:[http://en.cppreference.com/w/cpp/utility/make_from_tuple|cppreference documentation]).
header are ported here to previous versions:
* is_lvalue_reference and is_rvalue_reference mapped from C++11 to C++03.
* is_null_pointer from C++14 to previous Standards.
* triviality traits (is_trivially_xxxx) for C++03.
* make_void from C++17 to previous Standards.
* Others.
TO BE ORGANIZED
declval
function to provide pseudovariables in unevaluated contexts, from C++11 to C++03.
* The exchange
function for pushing-in new values for variables, from C++14 to C++03, C++11.
* The as_const
helper for const_casts, from C++17 to all previous versions.
In C++03 mode, declval
returns lvalue-references.
For C++03 mode only:
* A pair03
class that implements std::pair with move capability.
The interface of this class is exact mirror to that of std::pair
except for lacking tuple piecewise construction, but it supports movable types and is itself move-constructible and movable.
integer_sequence
and index_sequence
.
cbegin
and cend
iterator accesors (see Iterator Helpers).