{"id":15047753,"url":"https://github.com/tcbrindle/span","last_synced_at":"2025-09-13T16:52:12.028Z","repository":{"id":33535397,"uuid":"130602619","full_name":"tcbrindle/span","owner":"tcbrindle","description":"Implementation of C++20's std::span for older compilers","archived":false,"fork":false,"pushed_at":"2023-02-14T10:45:48.000Z","size":237,"stargazers_count":351,"open_issues_count":18,"forks_count":38,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-26T04:13:25.871Z","etag":null,"topics":["cpp","cpp20","standard-library"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tcbrindle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-22T19:57:17.000Z","updated_at":"2025-05-25T21:15:50.000Z","dependencies_parsed_at":"2024-12-24T10:23:40.122Z","dependency_job_id":"93a7c3ad-57be-44ae-a9f8-8f86c452d06d","html_url":"https://github.com/tcbrindle/span","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tcbrindle/span","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcbrindle%2Fspan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcbrindle%2Fspan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcbrindle%2Fspan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcbrindle%2Fspan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcbrindle","download_url":"https://codeload.github.com/tcbrindle/span/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcbrindle%2Fspan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274996614,"owners_count":25387926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp20","standard-library"],"created_at":"2024-09-24T21:04:11.261Z","updated_at":"2025-09-13T16:52:11.988Z","avatar_url":"https://github.com/tcbrindle.png","language":"C++","readme":"\n[![Standard](https://img.shields.io/badge/c%2B%2B-11/14/17/20-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)\n[![License](https://img.shields.io/badge/license-BSL-blue.svg)](http://www.boost.org/LICENSE_1_0.txt)\n[![Build Status](https://travis-ci.org/tcbrindle/span.svg?branch=master)](https://travis-ci.org/tcbrindle/span)\n[![Build status](https://ci.appveyor.com/api/projects/status/ow7cj56s108fs439/branch/master?svg=true)](https://ci.appveyor.com/project/tcbrindle/span/branch/master)\n[![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/-vlZZR) \n\n`std::span` implementation for C++11 and later\n==============================================\n\nThis repository contains a single-header implementation of C++20's `std::span`,\nconforming to the C++20 committee draft.\nIt is compatible with C++11, but will use newer language features if they\nare available.\n\nIt differs from the implementation in the [Microsoft GSL](https://github.com/Microsoft/GSL/)\nin that it is single-header and does not depend on any other GSL facilities. It\nalso works with C++11, while the GSL version requires C++14.\n\nUsage\n-----\n\nThe recommended way to use the implementation simply copy the file `span.hpp`\nfrom `include/tcb/` into your own sources and `#include` it like\nany other header. By default, it lives in namespace `tcb`, but this can be\ncustomised by setting the macro `TCB_SPAN_NAMESPACE_NAME` to an appropriate string\nbefore `#include`-ing the header -- or simply edit the source code.\n\nThe rest of the repository contains testing machinery, and is not required for\nuse.\n\nCompatibility\n-------------\n\nThis implementation requires a conforming C++11 (or later) compiler,  and is tested as far\nback as GCC 5, Clang 3.5 and MSVC 2015 Update 3. Older compilers may work, but this is not guaranteed.\n\nDocumentation\n-------------\n\nDocumentation for `std::span` is available [on cppreference](https://en.cppreference.com/w/cpp/container/span).\n\nImplementation Notes\n--------------------\n\n### Bounds Checking ###\n\nThis implementation of `span` includes optional bounds checking, which is handled\neither by throwing an exception or by calling `std::terminate()`.\n\nThe default behaviour with C++14 and later is to check the macro `NDEBUG`:\nif this is set, bounds checking is disabled. Otherwise, `std::terminate()` will\nbe called if there is a precondition violation (i.e. the same behaviour as\n`assert()`). If you wish to terminate on errors even if `NDEBUG` is set, define\nthe symbol `TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION` before `#include`-ing the\nheader.\n\nAlternatively, if you want to throw on a contract violation, define\n`TCB_SPAN_THROW_ON_CONTRACT_VIOLATION`. This will throw an exception of an\nimplementation-defined type (deriving from `std::logic_error`), allowing\ncleanup to happen. Note that defining this symbol will cause the checks to be\nrun even if `NDEBUG` is set.\n\nLastly, if you wish to disable contract checking even in debug builds,\n`#define TCB_SPAN_NO_CONTRACT_CHECKING`.\n\nUnder C++11, due to the restrictions on `constexpr` functions, contract checking\nis disabled by default even if `NDEBUG` is not set. You can change this by\ndefining either of the above symbols, but this will result in most of `span`'s\ninterface becoming non-`constexpr`.\n\n### `constexpr` ###\n\nThis implementation is fully `constexpr` under C++17 and later. Under earlier\nversions, it is \"as `constexpr` as possible\".\n\nNote that even in C++17, it is generally not possible to declare a `span`\nas non-default constructed `constexpr` variable, for the same reason that you\ncannot form a `constexpr` pointer to a value: it involves taking the address of\na compile-time variable in a way that would be visible at run-time.\nYou can however use a `span` freely in a `constexpr` function. For example:\n\n```cpp\n// Okay, even in C++11\nconstexpr std::ptrdiff_t get_span_size(span\u003cconst int\u003e span)\n{\n    return span.size();\n}\n\nconstexpr int arr[] = {1, 2, 3};\nconstexpr auto size = get_span_size(arr); // Okay\nconstexpr span\u003cconst int\u003e span{arr}; // ERROR -- not a constant expression\nconstexpr const int* p = arr; // ERROR -- same\n```\n\nConstructor deduction guides are provided if the compiler supports them. For\nolder compilers, a set of `make_span()` functions are provided as an extension\nwhich use the same logic, for example:\n\n   ```cpp\n   constexpr int c_array[] = {1, 2, 3};\n   std::array\u003cint, 3\u003e std_array{1, 2, 3};\n   const std::vector\u003cint\u003e vec{1, 2, 3};\n\n   auto s1 = make_span(c_array);   // returns span\u003cconst int, 3\u003e\n   auto s2 = make_span(std_array); // returns span\u003cint, 3\u003e\n   auto s3 = make_span(vec);       // returns span\u003cconst int, dynamic_extent\u003e\n   ```\n\nAlternatives\n------------\n\n* [Microsoft/GSL](https://github.com/Microsoft/GSL): The original `span` reference\n  implementation from which `std::span` was born.\n  \n* [martinmoene/span_lite](https://github.com/martinmoene/span-lite): An\n  alternative implementation which offers C++98 compatibility.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcbrindle%2Fspan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcbrindle%2Fspan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcbrindle%2Fspan/lists"}