Relative Content

Tag Archive for c++c++17

Can C++ conditional variables be used with std::scoped_lock?

std::condition_variable works only with std::unique_lockstd::mutex, which allows for maximal efficiency on some platforms. std::condition_variable_any provides a condition variable that works with any BasicLockable object, such as std::shared_lock.

Code optimization or how to speed up code

Given a number n, print all correct parenthesis sequences of parentheses and square brackets of length n in lexicographical order. You must enter an integer $n$ from 0 to 16 inclusive. The output should be “Print all valid parenthesis sequences of length n parentheses and square brackets in lexicographical order. Each sequence should be printed on a new line”

Incomprehensible operation of the skin and memory

To check how well her students can count, Maria Ivanovna assigns them the same problem every year – for a given natural number ( A ), find the smallest natural number ( N ) such that ( N ) to the power of ( N ) (i.e., ( N ) multiplied by itself ( N ) times) is divisible by ( A ). Each year, only the number ( A ) changes for each student. You have decided to help future generations. To do this, you need to write a program that solves this problem. The input file contains a single integer ( A ) (( 1 leq A leq 10^9 )). Just in case Maria Ivanovna decides to give a large number to challenge someone.

Initializing a std::string_view with a C-style string literal

std::string_view objects only have a view over an object such as a std::string, and modifying the value of a string used to initialize a string_view will invalidate it.
Now, if I initialize a string_view with a C-style string literal, as follows :
std::string_view s{ "Hello, world!" };