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.

Feature List

Here follows the list of features made available by 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].

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. (#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.

Standard Features

This is the "normal" feature set, which basically consists of backporting or integrating features from selected C++ headers. (#include , which also includes the above) * [Features/SequencesInitialization|Initialization of Sequences and Containers] * [#cxxo-algorithm|Features from ]: new copy, sort, shuffle algorithms. * [#cxxo-cstddef|Features from ]: nullptr_t, byte, etc. * [#cxxo-cstddint|Features from ]: typedefs for integral types. * [#cxxo-forward_list|Features from ], as in specifically std::forward_list. * [#cxxo-functional|Features from ], such as transparent functors. * [#cxxo-limits|Features from ], in particular constants for min/max. * [#cxxo-memory|Features from ], such as alignof and very especially "[#cxxo-unique_ptr|unique_ptr]" for dynamic management of objects. * [#cxxo-random|Features from ]: C++03 renames of the C++11 random utilities. * [#cxxo-string|Features from ], in particular to_string. * [#cxxo-tuple|Features from ], in particular tuple "apply". * [#cxxo-type_traits|Features from ] (partial implementation). * [#cxxo-utility|Features from ], in particular declval. * [#cxxo-utils|Other standard features] such as algorithms and utility functions not in their own section.

Cxxomfort Library Features

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

Cxxomfort Extras

The library also adds a number of backports or independent features that [Features/Extras|are considered separate and must be included individually for use], and mostly regard advanced features or C++ proposals.

Details

This library adds the features in a special namespace, ::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.

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 [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.

Static Assert

Implements: n1604, [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html|n1720].
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 [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).

Metaprogramming Helpers

Implementation of metaprogramming helpers such as identity, enable_if, etc. See [Features/MetaprogrammingHelpers]. (To be documented)

Iterator Access Functions

Implemented by 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 [c][begin,end] functions is overloaded to take container-like objects that define iterator types and C-like arrays, as well as 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.

Details of Standard Features

Features from

To enable these features, #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: // external struct is_odd_t { int operator() (int) const {...} } is_odd: // usage vector t, u; ... copy_if (begin(t), end(t), back_inserter(u), is_odd); assert (all_of(begin(u), end(u), is_odd); u.sort(); assert (is_sorted(begin(u), end(u)); * (TOBEDONE) The "shuffle" and "random_shuffle" algorithms.

Features from

To enable these features, #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 is also provided separately. This enables access to a number of features from C++ that are declared in the 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).

Features from

To enable these features, #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|] header is also provided separately. This enables access to a number of features from C++11 onwards, specifically the typedefs for integral types such as uint16_t, int64_t, etc.

Features from

To enable these features, #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|] header is also provided separately. This header adds barebones, mostly usable support for the "forward_list" sequence container in C++03. A 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.

Features from

To enable these features, #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: // Generically "join" a sequence using the % operator, if so defined class SumType; struct Sum { template SumType operator() (SequenceType const& ss) const { return accumulate (begin(vi), end(vi), modulus() ); } }; SumType s; vector vi; ...; // add content to vi somehow s= Sum()(vi); // <-- call does not need to be made aware of the type of vi's elements vector vt; ...; // add content to vt somehow s= Sum()(vt); // <-- call does not need to be made aware of the type of vt's elements

Features from

To enable these features, #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.

Features from

To enable these features, #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: template class integral_limits { // members from std::numeric_limits static const integral const_min = INTGRL_MIN; // implementation-defined static const integral const_max = INTGRL_MAX; // implementation-defined template digits_base { uint value; }; }; For example, 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.

Features from

To enable these features, #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 Pointer

Implemented by unique_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.

Features from

To enable these features, #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|] header is also provided separately. This enables access to a number of features from later C++11 additions in C++03: * Renames of the random utilities in that changed name in C++11 onward, for example std::tr1::uniform_int_distribution for std::tr1::uniform_int.

Features from

To enable these features, #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: time_t tt= time(0); struct tm tx; localtime_r(&tt,&tx); using namespace cxxomfort::string; // brings variadic to_string in string s= to_string(tx.tm_hour, ':', setw(2), setfill('0'), tx.tm_min); cout<< s<< endl;

Features from

To enable these features, #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]).

Features from

Various interfaces from C++'s 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

Features from

The following interfaces are brought in from their C++ versions to previous standards: * The 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. template class pair03 { pair03 (); pair03 (pair03 const&); pair03 (rvref &); // move-emulation constructor template pair03 (pair03 const&); TA first; TB second; // various operators... }; For C++11 mode only: * An implementation of integer_sequence and index_sequence.

Standard C++ Utilities

The following utilities defined in C++11 in other header files are added to C++03 with this library: * The "[http://en.cppreference.com/w/cpp/algorithm/iota|iota]" algorithm. (External link) The following utilities defined in C++14 are added to C++03/11 with this library: * The global cbegin and cend iterator accesors (see Iterator Helpers).
* [BehaviourMacros] * [Features/Extras] * [IndependentFeatures] * [Cxxomfort|Back to the beginning] Z dd8ab69ab09202f723c1a436c419896e