...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::process::v2::basic_cstring_ref — Small wrapper for a null-terminated string that can be directly passed to C APIS.
// In header: <boost/process/v2/cstring_ref.hpp> template<typename CharT, typename Traits = std::char_traits<CharT> > struct basic_cstring_ref { // types typedef CharT value_type; typedef Traits traits_type; typedef basic_string_view< value_type, Traits > string_view_type; typedef CharT * pointer; typedef const CharT * const_pointer; typedef CharT & reference; typedef const CharT & const_reference; typedef const_pointer const_iterator; typedef const_iterator iterator; typedef typename std::reverse_iterator< const_iterator > const_reverse_iterator; typedef typename std::reverse_iterator< iterator > reverse_iterator; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // public member functions basic_cstring_ref() noexcept; basic_cstring_ref(std::nullptr_t) = delete; basic_cstring_ref(const value_type *); template<typename Source, typename = typename std::enable_if< std::is_same<const value_type, typename std::remove_pointer<decltype(std::declval<Source>().c_str())>::type >::value, ::type> basic_cstring_ref(Source &&); constexpr basic_string_view< value_type, Traits >::const_pointer c_str() const noexcept; constexpr operator string_view_type() const; constexpr const_iterator begin() const noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; constexpr size_type size() const noexcept; constexpr size_type length() const noexcept; constexpr size_type max_size() const noexcept; constexpr bool empty() const noexcept; constexpr const_reference operator[](size_type) const; constexpr const_reference at(size_type) const; constexpr const_reference front() const; constexpr const_reference back() const; constexpr const_pointer data() const noexcept; constexpr void remove_prefix(size_type); void swap(basic_cstring_ref &) noexcept; size_type copy(value_type *, size_type, size_type = 0) const; constexpr basic_cstring_ref substr(size_type = 0) const; constexpr string_view_type substr(size_type, size_type) const; constexpr int compare(basic_cstring_ref) const noexcept; constexpr bool starts_with(string_view_type) const noexcept; constexpr bool starts_with(value_type) const noexcept; constexpr size_type find(CharT, size_type = 0) const noexcept; void clear() noexcept; std::basic_string< value_type, traits_type > to_string() const; template<typename Allocator> std::basic_string< value_type, traits_type, Allocator > to_string(const Allocator &) const; // private static functions static constexpr const_pointer null_char_(); // public data members static constexpr size_type npos; };
This ref can only be modified by moving the front pointer. It does not store the size, but can detect values that can directly be passed to system APIs.
It can be constructed from a char*
pointer or any class that has a c_str()
member function, e.g. std::string or boost::static_string.
basic_cstring_ref
public member functionsbasic_cstring_ref() noexcept;
basic_cstring_ref(std::nullptr_t) = delete;
basic_cstring_ref(const value_type * s);
template<typename Source, typename = typename std::enable_if< std::is_same<const value_type, typename std::remove_pointer<decltype(std::declval<Source>().c_str())>::type >::value, ::type> basic_cstring_ref(Source && src);
constexpr basic_string_view< value_type, Traits >::const_pointer c_str() const noexcept;
constexpr operator string_view_type() const;
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator cend() const noexcept;
constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const;
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const_pointer data() const noexcept;
constexpr void remove_prefix(size_type n);
void swap(basic_cstring_ref & s) noexcept;
size_type copy(value_type * s, size_type n, size_type pos = 0) const;
constexpr basic_cstring_ref substr(size_type pos = 0) const;
constexpr string_view_type substr(size_type pos, size_type length) const;
constexpr int compare(basic_cstring_ref x) const noexcept;
constexpr bool starts_with(string_view_type x) const noexcept;
constexpr bool starts_with(value_type x) const noexcept;
constexpr size_type find(CharT ch, size_type pos = 0) const noexcept;
void clear() noexcept;
std::basic_string< value_type, traits_type > to_string() const;
template<typename Allocator> std::basic_string< value_type, traits_type, Allocator > to_string(const Allocator & a) const;