Skip to content

A custom implementation of the C++17 'string_view' back-ported to c++11

License

Notifications You must be signed in to change notification settings

bitwizeshift/string_view-standalone

Repository files navigation

string_view Standalone

Ubuntu Build Status macOS Build Status Windows Build Status Coverage Status Github Issues
Github Releases Tested Compilers Documentation GitHub License

What is string_view Standalone?

C++17 introduced lightweight, non-owning strings referred to as string_view to the standard. Unlike std::string, which performs memory allocations and copies for most string operations (such as substr), the string_view only observes and does not modify the entry. This can massively decrease the memory footprint and provide a large optimization for immutable strings for things like parsing and tokenization. As a result, such a type can be an asset in older c++ versions for systems that may not support the newer standards.

The full type, basic_string_view is templated on a both CharT and Traits to allow viewing of contiguous char-like sequences of data, and for simple conversion between std::basic_string and basic_string_view.


This string_view implementation is from the BackportCpp library, which aims to backport library types and utilities from C++14, C++17, and C++20 to be compatible with C++11 compilers. This standalone library simply offers a subset for those looking for a simple drop-in string_view implementation.

Rationale

C++17 is still undergoing the standardization process (although currently is considered 'feature-complete'). Although non-owning strings are available in many other libraries, such as boost, Bloomberg STD, QT -- all of them come with rather large dependencies and have slightly different functionality and signatures.

By releasing this library as a standalone include, it provides future-proof support to older compilers with easy accessibility. It also allows using the newer feature-set in older versions, and facilitates easy upgrades to the new standard as compilers upgrade and newer c++ versions become available.

Tested Compilers

The following compilers are currently being tested through continuous integration with Travis.

Note that bpstd::string_view only works on compiler that provide proper conformance for c++11, meaning this does not properly work on g++ before 4.8

Compiler Operating System
g++ 4.9.3 Ubuntu 14.04.3 TLS
g++ 5.3.0 Ubuntu 14.04.3 TLS
g++ 6.1.1 Ubuntu 14.04.3 TLS
clang 3.5.0 Ubuntu 14.04.3 TLS
clang 3.6.2 Ubuntu 14.04.3 TLS
clang 3.8.0 Ubuntu 14.04.3 TLS
clang xcode 6.0 Darwin Kernel 13.4.0 (OSX 10.9.5)
clang xcode 6.1 Darwin Kernel 14.3.0 (OSX 10.10.3)
clang xcode 7.0 Darwin Kernel 14.5.0 (OSX 10.10.5)
clang xcode 7.3 Darwin Kernel 15.5.0 (OSX 10.11.5)
clang xcode 8.0 Darwin Kernel 15.6.0 (OSX 10.11.6)
Visual Studio 14 2015 Windows Server 2012 R2 (x64)

License

The class is licensed under the MIT License:

Copyright © 2016-2021 Matthew Rodusek

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

References