W6: Intro to the Standard Library Flashcards
What component of the standard library is not declared in the std namespace?
The filesystem component
namespace filesystem
The string library provides support for three types of strings:
the string classes
the string_view classes
null terminated C-style string functions
String class specializations:
std: :string (>)
std: :wstring (>)
std: :u16string >)
std: :u32string >)
String class public member functions:
operator=
operator[]
size()
substr()
operator+=
- assigns a string to the current string
- accesses a specified character in the string
- the number of characters in the string
- returns a substring of the string
- append a character or a string to the current string
String class public member functions:
find(char c)
rfind(char c)
find_first_of(char c)
find_last_of(char c)
find_first_of(basic_string_view(const CharT* s))
find_last_of(basic_string_view(const CharT* s))
- find the first occurence of c in the string
- find the last occurence of c in the string
- find the first occurence of c in the string
- find the last occurence of c in the string
- find the first occurence of any character in the sequence s
- find the last occurence of any character in the sequence s
a string type keeps track of the number of characters in the string through an instance variable without using the null byte as a terminator. A string object can include one or more null byte (‘\0’) characters.
What is the output:
#include #include
int main() { std::string str("Hello"); str += '\0'; // adds a null byte str += " World"; // adds a string int i = 0; for (const auto& c : str) if (str[i++] == '\0') std::cout << "Null byte at str[" << i-1 << "]\n"; std::cout << str << std::endl; }
Null byte at str[5]
Hello World
string_view library characteristics:
- avoids redundant copying of strings
- does not own the string, read only
- read only view into a contiguous sequence of characters
string_view class specializations
std: :string_view (>)
std: :wstring_view (>)
std: :u16string_view >)
std: :u32string_view >)
What operators does the string_view class omit from the string class?
operator +=
operator»_space;
A complete programming solution to the implementation of a data structure requires:
the definition of the data type of each element in the data structure
the choice of the optimal data structure to collect the elements
the function object for the algorithm to use on the data structure
syntax to access the facilities of the STL
lvalue and rvalue Distinction
std: :ref() () - returns an lvalue reference to its argument
std: :move() () - returns an rvalue reference to its argument
C++17 introduced new library facilities. They include:
std::string_view () - a read-only contiguous sequence of characters (see above)
std::variant() () - represents a type-safe union
std::optional () - may or may not contain a value (beyond scope)
std::any () - single values of any type (beyond scope)
std::uncaught_exceptions () - stack is in the process of unwinding
Uniform container access std::size std::empty std::data - number of elements, emptiness, direct access to underlying array
Special Mathematical Functions () -= (beyond scope)
Filesystem Library filesystem:: () - facilities for performing operations on file systems and their components including paths, regular files and directories (beyond scope)
class template std::variant represents:
a type-safe union
The value of a variant can be accessed by
using its type if it’s unique
using its index
variant class template member functions include:
operator=(v) - assigns value of variant v to the left operand
index() - returns the index I of the variant stored in the current object