boost::urls::segments_view::segments_view :: Boost Libraries Documentation

# boost::urls::segments_view::segments_view

Constructor

## Synopsis

Declared in `<boost/url/segments_view.hpp>`

    segments_view(
        iterator first,
        iterator last) noexcept;

## Description

This function creates a new `segments_view` from a pair of iterators referring to elements of another segments view. The resulting view references the same underlying character buffer as the original.

The constructed view preserves the original absolute flag when `first` selects the first segment and otherwise produces an absolute subview: if the source path is relative and `first == ps.begin()` the new view is relative, and in every other case the subview is absolute with the separator immediately preceding `*first` retained at the front. This ensures the underlying text can be reconstructed by concatenating the buffers of adjacent subviews.

The caller is responsible for ensuring that the lifetime of the original buffer extends until the constructed view is no longer referenced.

## Example

    segments_view ps( "/path/to/file.txt" );

    segments_view sub(
        std::next(ps.begin()),
        ps.end());

    segments_view first_half(
        ps.begin(),
        std::next(ps.begin()));

    // sub represents "/to/file.txt"
    std::string combined(first_half.buffer());
    combined.append(sub.buffer());
    BOOST_ASSERT(combined == ps.buffer());

## Preconditions

The iterators must be valid and belong to the same `segments_view`.

## Postconditions

`sub.buffer()` references characters in the original `ps.buffer()`.

## Complexity

Constant

## Exception Safety

Throws nothing.

## Parameters

Name | Description
first | The beginning iterator.
last | The ending iterator.

Created with MrDocs