PrevUpHomeNext

Important Boost.Text Conventions

C++20's std::ranges::dangling

When you call an algorithm template<std::forward_range R> foo(R && r) in C++20, and you pass an rvalue for r that is not know to be a "borrowing range" like a view, the algorithm will often rerturn a std::ranges::dangling instead of the desired result. This will probably cause your code to be ill-formed if you try to use the result. This lets you catch errors like this:

// decltype(iter) is std::ranges::dangling.  If it were a proper iterator,
// "iter" would now be a dangerous dangling reference, and using it would
// cause your progam to have undefined behavior.
auto iter = std::ranges::find(std::vector<int>{/* ... */}, 42);

Boost.Text follows this convention. If you call an algorithm alg that returns an iterator or subrange, or that constructs a view, and you pass alg an rvalue range in which to do its work, it will return a std::ranges::dangling.

The as_ Prefix

Functions and view adaptors that begin with as_ operate on values that model utf_range_like. That is, they not only work with code_point_ranges and/or grapheme_ranges, but also null-terminated string pointers. For instance, for some char const * c_str = /* ... */, c_str | text::boost::as_utf32 creates a code point view of the contents of c_str, interpreting c_str as a null-terminated string.

[Note] Note

Any pointer to an integral type whose size is 8-, 16-, or 32-bits will be treated as a null-terminated string.


PrevUpHomeNext