Category "c++17"

value of set::find() if not found in container

I am trying to understand std::find(). Below is my code. std::set::find searches the container for an element equivalent to val and returns an iterator to it i

Can auto-vectorization be automatically done by #pragma omp simd? [duplicate]

In order to use auto-vectorization for a c++ code which will be running on x86-64 and aarch64 processors, is just adding #pragma omp simd in t

Overwrite elements in std::shared_ptr to array, what got wrong?

I have following header : #ifndef MY_TEMPLATE_CLASSES_H #define MY_TEMPLATE_CLASSES_H #pragma once #include <cstdio> #include <iostream> #include

std::execution breaks file writing

The program seems to exit without waiting for the file system to apply the inner changes when integrating with std::execution. I recently tried PPL, TBB, OpenMP

Visitor Pattern and std::shared_ptr

I am using the Visitor design pattern in my application for message processing. For example: class AbstractMessageVisitor; class AbstractMessage { public:

generic decorators for callable objects with conditional return

I want to write decorator functions for callable objects. This is what I have now: #include <utility> template <typename DecoratedT, typename Callable

How to check a type has constexpr constructor

I want my class use another implementation for types don't have constexpr constructor. like this: template <typename A> class foo { public: // if A h

How to find the count of sub numbers of size k which divide the number

Given a number n Find the count of the sub numbers of size x in a number num which divides num. For example, if the number is 250 and x=2 the answer will be 2 a

Linux read dilemma

I need to read from a fifo. Using ssize_t read(int fd, void *buf, size_t count);, I faced the following situation. When a large set of data must be read from fi

std::stringstream's seekg does not work after while loop

I have this std::stringstream object whose contents I have to read (only) twice. For this I thought I could use its seekg member function to repeat the reading.

Datetime parse and format in C++

I'm using time_point the first time. I want to parse datetime from string and found a difference when returning back to string from 1 hour. std::chrono::system_

How arrays with an empty size works in c++? [duplicate]

I'm reading some materials about C++ and I just saw that array can be declared without a size (ex. int arr[], char x[][10]) and I'm wondering

Expand variadic template template parameters for use in e.g. std::variant<T...>

This will be a hard nut to crack. I don't even know if it's possible. My goal is to create a receive function that listens to multiple queues and pastes the obj

What does std::filesystem::is_regular_file(path) mean on Windows?

About std::filesystem::is_regular_file(path), cppreference.com says: Checks if the given file status or path corresponds to a regular file […] Equivalen

Dynamically allocated structures are well initialised?

For POD structure, could new Demo_Class[CONST_NUMBER]() guarantee the dynamically allocated structures are well initialised(i.e. not garbage) in C++11 and after

Error Missing Type specifer - int assumed . Note C++ does not support default init

In order to make two objects, User1 and User2, of a class User sending and receiving messages, #include <iostream> using namespace std; class reply { p

How to print a n-dimensional c++ STL container? Container is array of arrays or vectors of vectors

I have a code where I want to display tensor represented as vectors of vectors or std::arrays of std::arrays. The intention is to print them the way numpy print

How to create a simple version of std::function class

Suppose that I want to create a simple version ofstd::function, which has following behaviors: 1. function(){} -> A void constructor 2. function(_ReturnType,

Ambiguous partial specializations and enable_if_t

This question is due to insane curiosity rather than an actual problem. Consider the following code: template<typename...> struct type_list {}; template&

How can I get a consistent, unique, identifier for a unique class combination?

I need a way to identify a unique combination of template types that gives me an easily indexable identifier. I have the following class: #include <cstdint&g