Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

A View to a String: Part I


January, 2006: A View to a String: Part I

Listing 1

template
template< typename C                       // Character type
        , typename T = std::char_traits<C> // Traits
        , typename A = std::allocator<C>   // Allocator
        >
class basic_string_view
  : private A
{
public: // Types
  typedef C                           value_type;
  typedef basic_string_view<C, T, A>  class_type;
  . . .
  typedef value_type const            &const_reference;
public: // Construction
  basic_string_view();
  basic_string_view(class_type const &rhs);
  basic_string_view(class_type const &s, size_type pos);
  basic_string_view(class_type const &s, size_type pos, size_type cch);
  basic_string_view(char_type const *s);
  basic_string_view(char_type const *s, size_type cch);
  basic_string_view(char_type const *first, char_type const *last);
  ~basic_string_view() throw();
  class_type &operator =(class_type const &rhs);
public: // Operations
  void  swap(class_type &other) throw();
  void  clear() throw();
  void  refresh() throw();
public: // Attributes
  size_type        size() const throw();
  size_type        length() const throw();
  static size_type max_size() throw();
  allocator_type   get_allocator() const;
  . . .
public: // Comparison
  bool equal(class_type const &rhs) const throw();
  bool equal(value_type const *rhs, size_type cchRhs) const throw();
  int compare(size_type pos, size_type cch
            , value_type const *s, size_type cchRhs) const throw();
  int compare(size_type pos, size_type cch
	   , value_type const *s) const throw();
  int compare(value_type const *s) const throw();
  int compare(size_type pos, size_type cch, class_type const &rhs
            , size_type posRhs, size_type cchRhs) const throw();
  int compare(size_type pos, size_type cch
	  , class_type const &rhs) const throw();
  int compare(class_type const &rhs) const throw();
public: // Accessors
  const_reference         operator [](size_type index) const;
  value_type const        *c_str() const;
  value_type const        *data() const throw();
  value_type const        *base() const throw();
  const_reference         front() const;
  const_reference         back() const;
  size_type               copy( value_type *dest, size_type cch
                              , size_type pos = 0) const throw();
public: // Iteration
  const_iterator          begin() const;
  const_iterator          end() const;
  const_reverse_iterator  rbegin() const;
  const_reverse_iterator  rend() const;
private: // Invariant
  bool  is_valid() const;
private: // Implementation
  static char_type const *empty_string_() throw();
  static int       compare_(char_type const *lhs, size_type lhs_len
                          , char_type const *rhs, size_type rhs_len);
private: // Members
  size_type         m_length;
  char_type const   *m_base;
  mutable char_type *m_cstr;
};

// and comparison operators ==, !=, <, <=, >, >=
template<   typename C
        ,   typename T
        ,   typename A
        >
bool operator ==(basic_string_view<C, T, A> const &lhs 	      , basic_string_view<C, T, A> const &rhs);
// ... and overloads for C const *. 


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.