Examples for using the cxxomfort backports library for C++ (http://ryan.gulix.cl/fossil.cgi/cxxomfort/) and its features.

Luis Machuca Bezzaza e8f4c9a5b9 Updated examples for cxxomfort 20200918 "The Covid Fonda Release". 8 months ago
examples e8f4c9a5b9 Updated examples for cxxomfort 20200918 "The Covid Fonda Release". 8 months ago
LICENSE 7273357b4b Initial commit 5 years ago
README.md e8f4c9a5b9 Updated examples for cxxomfort 20200918 "The Covid Fonda Release". 8 months ago

README.md

cxxomfort-examples

Examples for using the cxxomfort backports library


This is a set of usage examples for cxxomfort, the backports library for C++, intended both as a demonstration of the working features and as a provision of code samples when pointing users to the library.

Instructions

Have the cxxomfort library (version >= 20200101) installed. Pick the example you want and compile.

In order to work correctly, you can do any of the following:

  • Copy or link the cxxomfort/ directory of the distribution into your compiler's system search path (/usr/local/include/ or similar).
  • Add the path with -I /path/to/cxxomfort, or the equivalent option for your compiler / project.

Current Examples

The listing of examples includes but is not limited to:

1.- Showing information about cxxomfort and support.

  • 0info.cpp - shows basic information, in particular detected compiler setup.
  • 0showsupport.cpp - besides the above, shows specific information about features detected and supported by the library.

2.- Basic demonstrations - flexing one feature at a time.

  • byte.cpp - C++17's std::byte backport.
  • explicit_cast.cpp - explicit_cast and explicit conversion operator emulation.
  • gcd.cpp - gcd and the pre-C++14 static version static_gcd part of cxxomfort:library.
  • generic_errors.cpp - showcases the C++11 <system_error> features.
  • randonly.cpp - example use of utilities related to <random> as well as iterator accessors.
  • plus.cpp - backports of C++14's "heterogeneous functors" (plus<void> and the like), as well as foreach emulation.
  • string_view.cpp - backports of C++17's string_view utility, as well as showing related helpers.
  • to_string.cpp - C++11's to_string backport.
  • tuple_get.cpp - tuple<type> access elements by type, as well as testing features such as static_assert.

3.- Showcasing libraries and supplementals.

  • foreach.cpp - foreach loop emulation feature (equivalent to for (v : sequence) { ... }), part of cxxomfort:library; among other things.
  • to_string-improved.cpp - extended to_string proposal (p0117r0) in cxxomfort:library.
  • type_name.cpp cxxomfort:library's typeid_demangle and type_name<> utilities.
  • typesafe_enum.cpp showcases the typesafe enum implementation, an alternative to C++11's enum class.

4.- Examples adapted from external sources.

The examples in examples/cppref and examples/cplusplus have been adapted from the cppreference and cplusplus sites for use with cxxomfort.

  • invoke.cpp - the std::invoke example showcasing invocation of functions and function objects.
  • midpoint.cpp - the std::midpoint example for the new C++20 utility.
  • typeindex.cpp - std::type_index and its use in hashes.
  • unique_ptr.cpp - the unique_ptr<> example lifted from cppreference / cplusplus.

Notes

Testing Environments

Unless specified otherwise in any of the source files, these examples have been tested in most or all of the following environments:

  • GCC 4.6 without --std=c++0x
  • GCC 4.6 with --std=c++0x.
  • MSVC 2008 Express.
  • MSVC 2010 Express.

All compiler configurations and limitations apply as per cxxomfort manual's Per-Compiler Notes.

For more information read cxxomfort configuration.