• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    C++
  • Created almost 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++17 library facilities for older compilers

Collected C++17 Headers for C++11/14

This repository features self-contained single-header implementations of some of the new facilities which will be added to the standard library in C++17, namely std::any, std::optional, std::string_view and std::variant.

The intention is to make it easy for people to get started with the new libraries now, without having to wait for newer compiler versions. The headers are all backwards-compatible to C++11, except for variant.hpp which is C++14 only.

I am not the original author of any of these headers; my involvement extends to putting them together in one place, changing namespaces and adding a little bit of preprocessor code to prefer standard library versions when available. All credit should go to the original authors, whose details can be found below.

Usage

The recommended way to use these headers is to simply copy the ones you need into your own sources. (If you find this distasteful, and instead wish to add a dependency on this repo in your project, please consider whether you should add a dependency on Boost instead.) Each header is self-contained, and they can all be used independently.

These headers all use namespace stx ("standard extensions") by default. This can be customised by defining the symbol STX_NAMESPACE NAME to a suitable string before including the header, for example

#define STX_NAMESPACE_NAME myns
#include <stx/any.hpp>

myns::any i = 3;

Forward compatibility

Eventually, and hopefully in the not-too-distant future, all of these headers will be available as part of every standard library implementation. Many of them are already available in the std::experimental namespace in some compilers. For forward compatibility, these headers will try to use standard library versions if possible, and only fall back to the included implementations if this fails.

On compilers which implement __has_include() (only GCC and Clang at the time of writing), each header N.hpp will first look for the standard library header <N>; if this is found, the names will be made available in the configured namespace via using declarations. If <N> cannot be found, it will look for <experimental/N>, before finally falling back to the included implementation. So for example, GCC 6.1 includes an implementation of std::experimental::any; therefore

#include <stx/any.hpp>

static_assert(std::is_same<stx::any, std::experimental::any>::value, "");

will pass on that system. The objective is to provide a seamless upgrade path to standard library facilities as they are included with compiler releases, eventually rendering this repo redundant.

If, for ABI reasons, you'd rather stick with the versions defined in this header even if a newer standard library implementation becomes available, then define the preprocessor symbol STX_NO_STD_N, where N is ANY, OPTIONAL etc before including the header. This will short-circuit the __has_include() check.

As an aside: if anybody knows of a way to emulate __has_include() on other compilers, particularly MSVC, please let me know.

...or use Boost

All of these headers (with the exception of variant.hpp, which is quite different from Boost.Variant) are available in (near-)identical form as part of Boost. The intention of this repo is to provide these facilities to people who are unwilling to (or cannot) add a dependency on Boost. If this situation does not describe you, please consider using the Boost versions instead.

Headers

any.hpp

optional.hpp

string_view.hpp

variant.hpp

More Repositories

1

raytracer.hpp

Simple compile-time raytracer using C++17
C
688
star
2

flux

A C++20 library for sequence-orientated programming
C++
474
star
3

NanoRange

Range-based goodness for C++17
C++
357
star
4

span

Implementation of C++20's std::span for older compilers
C++
326
star
5

sdl2-cmake-scripts

CMake scripts for finding SDL2 headers and libraries on multiple platforms
CMake
325
star
6

libflow

C++
62
star
7

numeris_romanis

Roman numeral support for C++17
C++
51
star
8

utf_ranges

A collection of Unicode utilities for C++ using Range-V3
C++
43
star
9

numeric_ranges

Numeric algorithms for C++20 Ranges
C++
30
star
10

gsound

GObject wrapper for libcanberra
C
13
star
11

rational

Single-header rational number library for C++14
C++
12
star
12

thinmatrix-gl-tutorials

C
10
star
13

systemd-glib

GObject bindings for the systemd D-Bus API
Vala
6
star
14

gvs

Work-in-progress GObject to GVariant serialization library
C
6
star
15

pretty_print.hpp

Single-header pretty-printing library for STL-compatible containers
C++
6
star
16

advent_of_code_2023

C++
6
star
17

modern-io

Modern IO library for C++
C++
5
star
18

leftpad

Of course I'm serious
C++
4
star
19

advent_of_code_2018

C++17/20 solutions for 2018's Advent of Code
C++
4
star
20

unicode.hpp

Unicode utilities for C++
C++
3
star
21

advent_of_code_2022

C++
3
star
22

sdlxx

Modern C++ binding for SDL2
C++
3
star
23

libsudoku

C and C++14 library for solving sudoku puzzles, using Range-V3
C++
2
star
24

advent_of_code_2020

C++
2
star
25

advent_of_code_2021

C++
1
star
26

wg21papertemplate

A LaTeX template for ISO C++ committee (aka WG21) papers.
TeX
1
star
27

variant

Clone of https://bitbucket.org/anthonyw/variant
C++
1
star