Examples for using the cxxomfort backports library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



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.


Have the cxxomfort library (version >= 20180801) 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

  • examples/0info.cpp - basic information about the library and the 'info' variable.
  • examples/0info.cpp - extended information about the library and about what features and compiler support have been found.
  • examples/byte.cpp - C++17's std::byte backport.
  • examples/explicit_cast.cpp - example usage of explicit_cast and explicit conversion operator emulation.
  • examples/foreach.cpp - foreach loop emulation feature (equivalent to for (v : sequence) { ... }), part of cxxomfort:library; among other things.
  • examples/gcd.cpp - gcd and the pre-C++14 static version static_gcd part of cxxomfort:library.
  • examples/plus.cpp - backports of C++14's "heterogeneous functors" (plus<void> and the like), as well as foreach emulation.
  • examples/randonly.cpp - example use of utilities related to <random> as well as iterator accessors.
  • examples/to_string.cpp - to_string backport.
  • examples/to_string-improved.cpp - variadic to_string proposal (p0117r0), part of cxxomfort::library.
  • examples/tuple_get.cpp - tuple<type> access elements by type, as well as testing features such as static_assert.
  • examples/type_name.cpp cxxomfort:library's typeid_demangle and type_name<> utilities.
  • examples/typesafe_enum.cpp showcases the typesafe enum implementation, an alternative to C++11's enum class.
  • examples/unique_ptr.cpp - the unique_ptr<> example lifted from cppreference.


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.

GCC limitations

GCC in C++03 mode does not allow for adding tr1/ to the compiler search path due to a bug. A TR1 forwarder has to be used according to the cxxomfort documentation; the examples here are compiled using tr1_fwd.

For more information read cxxomfort configuration.

MSVC limitations

MSVC 2008 Express does not include a working TR1 in its default install. Other than providing your own via eg.: Boost.TR1 or nononsenseboost.TR1, the best option is to install MSVC 2008 Express SP1.

For more information read cxxomfort configuration.