| Home | Libraries | People | FAQ | More

## Class template basic_string

boost::compute::basic_string — A template for a dynamically-sized character sequence.

## Synopsis

    // In header: <boost/compute/container/basic_string.hpp>

    template<typename CharT, typename Traits = std::char_traits<CharT> >
    class basic_string {
    public:
      // types
      typedef Traits                                                    traits_type;
      typedef Traits::char_type                                         value_type;
      typedef size_t                                                    size_type;
      typedef ::boost::compute::vector< CharT >::reference              reference;
      typedef ::boost::compute::vector< CharT >::const_reference        const_reference;
      typedef ::boost::compute::vector< CharT >::iterator               iterator;
      typedef ::boost::compute::vector< CharT >::const_iterator         const_iterator;
      typedef ::boost::compute::vector< CharT >::reverse_iterator       reverse_iterator;
      typedef ::boost::compute::vector< CharT >::const_reverse_iterator const_reverse_iterator;

      // public member functions
      basic_string();
      basic_string(size_type, CharT);
      basic_string(const basic_string &, size_type, size_type = npos);
      basic_string(const char *, size_type);
      basic_string(const char *);
      template<typename InputIterator> basic_string(InputIterator, InputIterator);
      basic_string(const basic_string< CharT, Traits > &);
      basic_string< CharT, Traits > &
      operator=(const basic_string< CharT, Traits > &);
      ~basic_string();
      reference at(size_type);
      const_reference at(size_type) const;
      reference operator[](size_type);
      const_reference operator[](size_type) const;
      reference front();
      const_reference front() const;
      reference back();
      const_reference back() const;
      iterator begin();
      const_iterator begin() const;
      const_iterator cbegin() const;
      iterator end();
      const_iterator end() const;
      const_iterator cend() const;
      reverse_iterator rbegin();
      const_reverse_iterator rbegin() const;
      const_reverse_iterator crbegin() const;
      reverse_iterator rend();
      const_reverse_iterator rend() const;
      const_reverse_iterator crend() const;
      bool empty() const;
      size_type size() const;
      size_type length() const;
      size_type max_size() const;
      void reserve(size_type);
      size_type capacity() const;
      void shrink_to_fit();
      void clear();
      void swap(basic_string< CharT, Traits > &);
      basic_string< CharT, Traits > substr(size_type = 0, size_type = npos) const;
      size_type find(CharT, size_type = 0) const;
      size_type find(basic_string &, size_type = 0) const;
      size_type find(const char *, size_type = 0) const;

      // public data members
      static const size_type npos;
    };

## Description

The `basic_string` class provides a generic template for a dynamically- sized character sequence. This is most commonly used through the `string` typedef (for `basic_string<char>`).

For example, to create a string on the device with its contents copied from a C-string on the host:

    boost::compute::string str("hello, world!");

See Also: vector<T>

### `basic_string` public member functions

1.     basic_string();

2.     basic_string(size_type count, CharT ch);

3.     basic_string(const basic_string & other, size_type pos,
                    size_type count = npos);

4.     basic_string(const char * s, size_type count);

5.     basic_string(const char * s);

6.     template<typename InputIterator>
         basic_string(InputIterator first, InputIterator last);

7.     basic_string(const basic_string< CharT, Traits > & other);

8.     basic_string< CharT, Traits > &
       operator=(const basic_string< CharT, Traits > & other);

9.     ~basic_string();

10.     reference at(size_type pos);

11.     const_reference at(size_type pos) const;

12.     reference operator[](size_type pos);

13.     const_reference operator[](size_type pos) const;

14.     reference front();

15.     const_reference front() const;

16.     reference back();

17.     const_reference back() const;

18.     iterator begin();

19.     const_iterator begin() const;

20.     const_iterator cbegin() const;

21.     iterator end();

22.     const_iterator end() const;

23.     const_iterator cend() const;

24.     reverse_iterator rbegin();

25.     const_reverse_iterator rbegin() const;

26.     const_reverse_iterator crbegin() const;

27.     reverse_iterator rend();

28.     const_reverse_iterator rend() const;

29.     const_reverse_iterator crend() const;

30.     bool empty() const;

31.     size_type size() const;

32.     size_type length() const;

33.     size_type max_size() const;

34.     void reserve(size_type size);

35.     size_type capacity() const;

36.     void shrink_to_fit();

37.     void clear();

38.     void swap(basic_string< CharT, Traits > & other);

39.     basic_string< CharT, Traits >
        substr(size_type pos = 0, size_type count = npos) const;

40.     size_type find(CharT ch, size_type pos = 0) const;

    Finds the first character `ch`.

41.     size_type find(basic_string & str, size_type pos = 0) const;

    Finds the first substring equal to `str`.

42.     size_type find(const char * s, size_type pos = 0) const;

    Finds the first substring equal to the character string pointed to by `s`. The length of the string is determined by the first null character.

    For example, the following code

    will return 5 as position.