Commit Graph

14 Commits

Author SHA1 Message Date
Marc Chevrier
8d4a9ee398 Refactoring: rename "cm_static_string_view.hxx" as <cmext/string_view> 2020-04-30 09:53:27 +02:00
Marc Chevrier
8f839d02e3 cm::String: enhance compatibility with STL 2020-01-25 18:16:16 +01:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Marc Chevrier
c688b401d3 cmstd: Modernize CMake system headers
Provide a standardized way to handle the C++ "standard" headers
customized to be used with current CMake C++ standard constraints.
Offer under directory `cm` headers which can be used as direct
replacements of the standard ones.  For example:

    #include <cm/string_view>

can be used safely for CMake development in place of the `<string_view>`
standard header.

Fixes: #19491
2019-09-20 10:01:37 -04:00
Regina Pfeifer
a1ddf2d0ba clang-tidy: Replace typedef with using
Automate the conversion with

  perl -i -0pe 's/typedef ([^;]*) ([^ ]+);/using $2 = $1;/g'

then manually fix a few places.
2019-09-04 18:03:01 +02:00
Regina Pfeifer
62e5f72289 clang-tidy: Replace typedef with using 2019-09-03 13:21:26 -04:00
Brad King
de0a2354fc IWYU: Add missing cstddef includes for size_t and nullptr_t
The IWYU tool we use for CI now diagnoses these.
2019-09-03 11:46:52 -04:00
Brad King
cd0881be61 IWYU: Update CMake code for IWYU built with Clang 6
IWYU now correctly requires `<utility>` for `std::move`.  It also
requires a container header when used via a range-based for loop.
2019-01-15 10:00:50 -05:00
Regina Pfeifer
32cb564bea clang-tidy: Remove redundant member initializations 2018-12-15 10:51:47 +01:00
Brad King
2d68b2c593 String: Add str_if_stable() as a const alternative to str()
The `str()` method must be non-const because it may need to internally
mutate the representation of the string in order to have an owned
`std::string` instance holding the exact string (not a superstring).
This is inconvenient in contexts where we can ensure that no mutation
is needed to get a `std::string const&`.

Add a `str_if_stable() const` method that returns `std::string const*`
so we can return `nullptr` if if mutation would be necessary to get a
`std::string const&`.  Add supporting `is_stable() const` and
`stabilize()` methods to check and enforce stable availability of
`std::string const&`.  These can be used to create `String const`
instances from which we can still get a `std::string const&` via
`*str_if_stable()` by maintaining the stability invariant at runtime.
2018-12-12 08:10:16 -05:00
Brad King
a0841b59bd String: Add support for a ""_s string literal syntax
Create a `static_string_view` type that binds only to the static storage
of string literals.  Teach `cm::String` to borrow from these implicitly.
2018-12-12 08:10:15 -05:00
Brad King
9d5fe8e96a String: Add 'borrow' member to construct borrowing instances
This will allow creation of `cm::String` instances that borrow from
non-owned storage.  It is the caller's responsibility to ensure that
no copy of the instance outlives the borrowed buffer.
2018-12-12 08:10:15 -05:00
Brad King
80802a002c String: Add support for concatenation by operator+
Use expression templates to collect the entire expression and
pre-allocate a string with the final length before concatenating
the pieces.
2018-12-12 08:10:15 -05:00
Brad King
ff69763ca0 String: Add a custom string type
Create a `cm::String` type that holds a view of a string buffer and
optionally shares ownership of the buffer.  Instances can either
borrow longer-lived storage (e.g. static storage of string literals)
or internally own a `std::string` instance.  In the latter case,
share ownership with copies and substrings.  Allocate a new internal
string only on operations that require mutation.

This will allow us to recover string sharing semantics that we
used to get from C++98 std::string copy-on-write implementations.
Such implementations are not allowed by C++11 so code our own in
a custom string type instead.
2018-12-12 08:10:15 -05:00