Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# core.stdcpp.string

D header file for interaction with C++ std::string.
License:
Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)
Authors:
Guillaume Chatelet Manu Evans

Source core/stdcpp/string.d

enum DefaultConstruct `Default`;
  Constructor argument for default construction
struct `char_traits`(CharT);
  Character traits classes specify character properties and provide specific semantics for certain operations on characters and sequences of characters.
struct `basic_string`(T, Traits = char_traits!T, Alloc = allocator!T);
  D language counterpart to C++ std::basic_string.
  C++ reference:
  enum size_type `npos`;
  alias `size_type` = size_t;
  alias `difference_type` = ptrdiff_t;
  alias `value_type` = T;
  alias `traits_type` = Traits;
  alias `allocator_type` = Alloc;
  alias `pointer` = value_type*;
  alias `const_pointer` = const(value_type)*;
  alias `toString` = as_array;
  this();
    MSVC allocates on default initialisation in debug, which can't be modelled by D struct
  alias `length` = size;
  alias `opDollar` = length;
  const nothrow @safe bool `empty`();
  const pure nothrow @nogc @safe size_t[2] `opSlice`(size_t dim : 0)(size_t `start`, size_t `end`);
  inout pure nothrow @nogc ref @safe inout(T) `opIndex`(size_t `index`);
  inout pure nothrow @nogc @safe inout(T)[] `opIndex`(size_t[2] `slice`);
  inout pure nothrow @nogc @safe inout(T)[] `opIndex`();
  const pure nothrow @safe bool `opEquals`(ref scope const basic_string `s`);
  const pure nothrow @safe bool `opEquals`(scope const T[] `s`);
    Two basic_strings are equal if they represent the same sequence of code units.
  const pure nothrow @safe int `opCmp`(ref scope const basic_string `rhs`);
  const pure nothrow @safe int `opCmp`(scope const T[] `rhs`);
    Performs lexicographical comparison.
  const pure nothrow @nogc @safe size_t `toHash`();
    Hash to allow basic_strings to be used as keys for built-in associative arrays. The result will generally not be the same as C++ std::hash<std::basic_string<T>>.
  void `clear`();
  @trusted void `resize`(size_type `n`, T `c` = T(0));
  inout nothrow ref @safe inout(T) `front`();
  inout nothrow ref @safe inout(T) `back`();
  const nothrow @safe const(T)* `c_str`();
  ref basic_string `opAssign`()(auto ref basic_string `str`);
  ref basic_string `opAssign`(const(T)[] `str`);
  ref basic_string `opAssign`(T `c`);
  ref basic_string `opIndexAssign`(T `c`, size_t `index`);
  ref basic_string `opIndexAssign`(T `c`, size_t[2] `slice`);
  ref basic_string `opIndexAssign`(const(T)[] `str`, size_t[2] `slice`);
  ref basic_string `opIndexAssign`(T `c`);
  ref basic_string `opIndexAssign`(const(T)[] `str`);
  ref basic_string `opIndexOpAssign`(string op)(T `c`, size_t `index`);
  ref basic_string `opIndexOpAssign`(string op)(T `c`, size_t[2] `slice`);
  ref basic_string `opIndexOpAssign`(string op)(const(T)[] `str`, size_t[2] `slice`);
  ref basic_string `opIndexOpAssign`(string op)(T `c`);
  ref basic_string `opIndexOpAssign`(string op)(const(T)[] `str`);
  ref basic_string `append`(T `c`);
  ref basic_string `opOpAssign`(string op : "~")(const(T)[] `str`);
  ref basic_string `opOpAssign`(string op : "~")(T `c`);
  ref basic_string `insert`(size_type `pos`, ref const(basic_string) `str`);
  ref @trusted basic_string `insert`(size_type `pos`, ref const(basic_string) `str`, size_type `subpos`, size_type `sublen`);
  ref basic_string `insert`(S : size_type)(S `pos`, const(T)* `s`);
  ref basic_string `insert`(size_type `pos`, const(T)[] `s`);
  ref basic_string `erase`(size_type `pos` = 0);
  ref basic_string `erase`(size_type `pos`, size_type `len`);
  ref basic_string `replace`()(size_type `pos`, size_type `len`, auto ref basic_string `str`);
  ref basic_string `replace`()(size_type `pos`, size_type `len`, auto ref basic_string `str`, size_type `subpos`, size_type `sublen` = npos);
  ref basic_string `replace`(size_type `pos`, size_type `len`, const(value_type)[] `s`);
  ref basic_string `replace`(S : size_type)(S `pos`, size_type `len`, const(value_type)* `s`);
  @trusted void `push_back`(T `c`);
  void `pop_back`();
  this(DefaultConstruct);
  this(const(T)[] `str`);
  this(const(T)[] `str`, ref const(allocator_type) `al`);
  inout ref inout(Alloc) `get_allocator`();
  const nothrow @safe size_type `max_size`();
  const nothrow @safe size_type `size`();
  const nothrow @safe size_type `capacity`();
  inout @safe inout(T)* `data`();
  inout nothrow scope @trusted inout(T)[] `as_array`() return;
  inout nothrow ref @trusted inout(T) `at`(size_type `i`);
  ref basic_string `assign`(const(T)[] `str`);
  ref basic_string `assign`(const ref basic_string `str`);
  ref basic_string `append`(const(T)[] `str`);
  ref basic_string `append`(size_type `n`, T `c`);
  void `reserve`(size_type `_Newcap` = 0);
  void `shrink_to_fit`();
  ref basic_string `insert`(size_type `pos`, const(T)* `s`, size_type `n`);
  ref basic_string `insert`(size_type `pos`, size_type `n`, T `c`);
  ref basic_string `replace`(size_type `pos`, size_type `len`, const(T)* `s`, size_type `slen`);
  ref basic_string `replace`(size_type `_Off`, size_type `_N0`, size_type `_Count`, T `_Ch`);
  void `swap`(ref basic_string `_Right`);

Copyright © 1999-2022 by the D Language Foundation | Page generated by Ddoc on Thu Dec 15 17:30:04 2022