Questions tagged [c++17]

C++17 is the name of the C++ standard approved in 2017. It builds upon the previous C++14 standard, improving the core language and standard library, and adding a few new language features.

Filter by
Sorted by
Tagged with
5 votes
1 answer
115 views

Is the initialization order of global variables and static inline data members relative to each other guaranteed?

The code below is in the same translation unit and A::v is defined after x, why A::v is not initialized to "ok" ? #include <string> #include <iostream> std::string foo() { ...
konchy's user avatar
  • 655
-2 votes
0 answers
12 views

Adding a library boost c++ to CMake.txt file [duplicate]

I want add a boost c++ library, to my project, to Cmake file, what I've done: I downloaded a c++ boost library to my computer. Then I compiled the library itself. I downloaded Cmake and read docs, ...
Cooler's user avatar
  • 1
0 votes
0 answers
24 views

Eliminating use of binary_function and result_type

I am trying to update an abandoned open source library to C++11 and 17. It uses std::binary_function and its result_type in a way I am not sure how to remove. These features were deprecated in C++11 ...
Rob McDonald's user avatar
1 vote
2 answers
72 views

Unexpected copy in unpacking via structured bindings a returned tuple

I'm trying to use structured bindings to return an std::tuple<std::string, std::vector<std::string_view>>, which represents a string and string-views pointing to the said string. ...
jerin's user avatar
  • 101
0 votes
0 answers
38 views

std::optional<T> assignment operators

My reference is to options (4), (5) and (6) of std::optional::operator= Given the premise that The class template std::optional manages an optional contained value, i.e. a value that may or may not be ...
Vinod's user avatar
  • 1,041
0 votes
2 answers
58 views

C++ chrono convert string with microseconds precision to chrono object

I'm parsing SVN logs and they contain date/time with this format 2023-09-23T23:08:30.383815Z. I need to convert this to a time object (supposed std::chrono::steady_clock was the good format). However, ...
jpo38's user avatar
  • 20.9k
-2 votes
0 answers
19 views

Appearance of Residual Images When Moving Objects in a Qt Application 5.0

When I implement separate objects in different classes and synchronize them in a widget, residual images appear when moving. At first, I suspected that the issue was related to incorrectly set ...
tix01's user avatar
  • 1
0 votes
0 answers
60 views

Recursive Directory Iterator Issue on Windows 11 - Fails to Show Symbolic Linked Sub-folders

I am encountering an issue with a recursive directory iterator code snippet on Windows 11. The code is designed to traverse through sub-folders, including symbolic links. However, on Windows 11, it ...
ark1974's user avatar
  • 623
1 vote
1 answer
43 views

How to copy graph properties of one boost graph into another boost graph?

I have a boost graph with vertex , edge and graph properties. I want to make a copy of boost braph. I copied vertex and edge properties ( using copy_graph) of one boost graph into another one but ...
tushar's user avatar
  • 333
-3 votes
0 answers
39 views

error: expected primary-expression before token [closed]

I am trying build a data structure Vector,first i write a vector.h file as a total interface and define some feature: #pragma once using Rank = unsigned int; #define DEFAULT_CAPACITY 3 template <...
Yuhan Zhao's user avatar
-1 votes
1 answer
28 views

C++ Q: Illegal member initialization trying to set base class member in derived [duplicate]

EDITED: Removed the Base class being a template class, as this has no bearing on the issue as others have pointed out to me. It has been a while since working with basic C++ concepts, and specifically ...
David Carr's user avatar
0 votes
0 answers
38 views

Declaring a set of member functions by a template of a function type

This is simplified version of existind code, an interface for a message processing declared independant from definitions of messages: /** * @file msg_io.h */ struct MsgIO { virtual ~MsgIO() {} }; /*...
Swift - Friday Pie's user avatar
1 vote
3 answers
59 views

Aliasing type of incomplete template of template

I have been struggling with this for a couple days. I am porting some code to MacOS/AppleClang and we have very heavy templated code that builds correctly on MSVC but fails on clang (understandably, ...
LarrxX's user avatar
  • 55
1 vote
1 answer
40 views

delete constructor in C++: private/protected/public?

what is the best practice to delete constructor in C++: put it in private/protected/public ?: approach 1: class Foo{ public: Foo() = delete; } approach 2: class Foo{ protected: Foo() = delete; } ...
casaDePapel's user avatar
0 votes
0 answers
16 views

cookTriangleMesh access exception

PxTriangleMesh* PhysX::CreateTriangleMesh(const PxVec3* verts, const PxU32 numVerts , const PxU32* indexs, const PxU32 numIndexes, PxPhysics* physics, PxCooking* cooking) { // Create ...
shroow's user avatar
  • 1
0 votes
1 answer
31 views

In the context of inheritance in C++, how can a function in the derived class be invoked before the execution of the base class constructor?

this is an example program to demonstrate adapter pattern. In the context of inheritance in C++, how can a function in the derived class be invoked before the execution of the base class constructor? ...
Jestin's user avatar
  • 35
1 vote
2 answers
71 views

Nested std::conditional_t failed but using class specialization tricks OK? Why? [duplicate]

I have a traits class to call some invokables. It can accept whether range parameter or not. My code is below. #include <functional> #include <type_traits> template <typename ...
Alexander Chen's user avatar
-2 votes
0 answers
63 views

#include <filesystem> causes fatal error with g++ [closed]

I am trying #include <filesystem> but running g++ x.cpp ...causes this error: fatal error: filesystem No such file or directory #include <filesystem> ^ compilation ...
Lun's user avatar
  • 873
0 votes
0 answers
20 views

CPU thermal zone changes on run time [closed]

I have an GUI application that continously reads CPU temperature from a thermal zone file. I read the thermal zone when starting my application using "grep -rsl "pkg" /sys/devices/...
Het Daftary's user avatar
1 vote
0 answers
12 views

C++ OPC write string array using Softing OPC-Classic-SDK

I know this is the way to write floating point array Variant Data; DateTime CurrentTime; CurrentTime.now(); double* ArrayVar; Data.SafeArrayAccessData(Data....
kpm's user avatar
  • 11
0 votes
1 answer
59 views

Implementing template operator<< for std::pair<const char*, std::optional<T>> with Handling of Constant Values

I'm trying to write a template that implements operator<< for std::pair<const char*, std::optional<T>>. This operator is already implemented for types passed by value or passed by ...
Fanteria's user avatar
0 votes
2 answers
66 views

How to fix this void_t issue with templated class?

I have code like this: #include <type_traits> struct S1{}; struct S2{ void rbegin(){} void rend(){} }; template<typename S> struct S3{ void rbegin(){ S().rbegin(); ...
Nick's user avatar
  • 9,975
0 votes
0 answers
32 views

Producing a union of two maps at an intersection

Provided the code std::map<std::string, std::vector<std::string>> table1 = { {"fruit", {"apple", "banana", "cherry"}}, {"number", {...
ISeekTheWisdom's user avatar
3 votes
2 answers
152 views

Format an array with a line break every n values using {fmt}

Using the {fmt} library (the version from github), is there a way to format a long array so that there is a line break inserted after every n values? For example, say I have a vector of 22 doubles, ...
SU3's user avatar
  • 5,136
0 votes
0 answers
94 views

Do reinterpret_cast double* to unsigned long long* constitue a strict aliasing violation? [duplicate]

To give some context, I'm focusing the case of data serialization/deserialization without being dependent of the platform endianness. For integral types, we can use the bitwise-shifting operators for ...
Fareanor's user avatar
  • 5,948
-1 votes
0 answers
68 views

VSCode,C++17,string_view can not be included [closed]

i am running my c++ code on vscode,but it says:fatal error: string_view: No such file or directory,here is my code: #include <string_view> using namespace std; cppStandard in c_cpp_properties....
Leeyleo's user avatar
0 votes
1 answer
64 views

Non-mandatory copy elision in catch clause

Reference: Copy Elision Excerpts: Under the following circumstances, the compilers are permitted, but not required to omit the copy and move (since C++11) construction of class objects even if the ...
Vinod's user avatar
  • 1,041
0 votes
2 answers
80 views

Templates core headers bloating and explicit specialization of std::hash in cpp file in c++17

Suppose I got a core library in which I'm trying to add explicit specialization of std::hash for my core classes, including class Foo (and many others I'd like to also specialize std::hash with). Foo....
pandaman1234's user avatar
-2 votes
0 answers
23 views

Inquire about a book to learn a C++ language [closed]

I am a beginner in learning programming, and I found this book that seems simple and smooth in explanation to me, but how can I be sure that it is not bad? I searched for the best books for beginners, ...
Oday Allaham's user avatar
0 votes
1 answer
65 views

Making similar functions prettier?

So I have an sequence which calls different function which do similar things and have the same signature. { if(!calcFunc1(sameTypeA, sameTypeB) || !calcFunc2(sameTypeB, sameTypeC) || !...
kaziko ni's user avatar
0 votes
1 answer
45 views

Initialize polymorphic C array with references/pointers to temporary statically allocated objects in C++ [closed]

Question Is it possible to initialize a polymorphic C array (e.g. an array of type ParentClass*, containing pointers of type Subclass1*, Subclass2* etc.) with references/pointers to temporary objects ...
T. R. Bernstein's user avatar
-6 votes
0 answers
70 views

What does std::move mean? [duplicate]

I have this piece of code from a class template: bool dequeue(T& t) { //before below m_queue is checked //if it's empty first t=std::move(m_queue.front()); m_queue.pop() return ...
Krusty's user avatar
  • 1
0 votes
0 answers
45 views

How to get blocked on multiple resources?

I've got the below code that implements a thread-safe message queue. #pragma once #include <queue> #include <mutex> #include <condition_variable> template<class ElementType> ...
Caglayan DOKME's user avatar
0 votes
2 answers
65 views

How to modernize a parallel C-style matrix-vector multiplication implementation using e.g. `std::transform`?

I am trying to adapt my programming practices with more modern approaches that leverage STL containers, algorithms, execution-policies, etc. I developed a small test to experiment with modernizing my ...
Andreas Hadjigeorgiou's user avatar
0 votes
1 answer
20 views

C++ VsCode Debugger Extra Information Showing

[[enter image description here](https://i.stack.imgur.com/jFwW0.png)](https://i.stack.imgur.com/Mtxnp.png) For simple program At time of debugging String values for all its memory location and ...
rihanshu raj's user avatar
1 vote
1 answer
90 views

VS Code on macos: When trying to compile code in C++, "-std=gnu++14" appears before all the flags. How to delete it?

I am a beginner, using VSCode on macOS. Trying to iterate using square brackets which is requires C++17: for (auto [document_id, relevance] : documents) { cout << "{ document_id ...
Dany's user avatar
  • 13
1 vote
0 answers
38 views

Why are all the lines outputting blank except the very last line? [closed]

I am trying to read in a text file with 4 numbers on each line and output each line on the console but only the very last line in the text file is being outputted while the rest are outputted as ...
Jaisun Rattu's user avatar
1 vote
1 answer
58 views

Make base NVI virtual function private?

Imagine I have some NVI interface that allows for customization points via virtual functions. And those virtual functions are designated solely for customization within the NVI and should never be ...
Sergey Kolesnik's user avatar
-1 votes
0 answers
35 views

How to construct nlohmann::ordered_json objects and dumping them on the fly?

I'm having a hard time with Nlohmann Json - I want to construct a JSON which contains an array of several objects in a section, such as: {"Foo": [{Obj0}, {Obj1}, ..., {ObjN}]} but, from my ...
Emiliano Toledo's user avatar
0 votes
0 answers
70 views

Sharing global config variables between executable and static libraries via headers using namespace and inline static members

Im trying to share some common config variables between some of my related static libraries and enabling the variables to be initialized and set within the main function of an executable linking ...
Amir Rasti's user avatar
14 votes
1 answer
921 views

Is it really well defined to check pointer alignment using the pointer's integer value?

Is there a guaranteed (not implementation-defined!) way to check for pointer alignment? The most common way to query pointer alignment seems to be: convert to integer check whether the integer is a ...
Kietz's user avatar
  • 1,336
4 votes
1 answer
231 views

A byte type: std::byte vs std::uint8_t vs unsigned char vs char vs std::bitset<8>

C++ has a lot of types that vaguely describe the same thing. Assuming that we are compiling for an architecture where a byte is 8-bit, all of the following types are vaguely similar: std::byte std::...
Jan Schultke's user avatar
  • 20.5k
1 vote
2 answers
79 views

Is there anyway to restrict c++ template class parameters within one-to-one relationship?

For example, there is a template class: template<typename A, typename B> class Example; If a pair of (A, B) is specialized, then other types cannot specialized with A. For example, (B, C) is ...
lhh2001's user avatar
  • 21
0 votes
0 answers
88 views

std::all_of produces more code than simple for loop

I have a simple use-case for checking if elements of a container are non-zero. #include <algorithm> #include <vector> bool true_on_any_nonzero(std::vector<int>& v) { for(...
rookie's user avatar
  • 1,168
2 votes
1 answer
60 views

How do I fix my `Any` class code to output data correctly?

I am trying to simulate std::any, my idea is to use the base class pointer to point to different types of template derived classes, to implement the function of storing different types of data, like ...
Konvt's user avatar
  • 31
1 vote
2 answers
132 views

optimization-friendy vector casting/transformation

I don't beleive there exists a good answer for this question. Most of the answers suggest range-initialization or std::transform. And sometimes it is advised to "rely on a SmartCompiler™ to ...
Sergey Kolesnik's user avatar
0 votes
0 answers
48 views

child class of CListCtrl cannot refresh display but still active

I'm coding an app, using C++17 standards and graphical library MFC. I have two virtual classes, ViewerGet and ViewerSet, that both inherit from Viewer class, that inherits from CListCtrl class from ...
liebhurnout's user avatar
0 votes
0 answers
16 views

How to create Enclave using Intel SGX SDK on LINUX

I am seeking assistance and guidance regarding Intel Software Guard Extensions (SGX) technology. I have successfully installed and built the Intel SGX SDK ,SGX Driver and Platform Software (PSW) on my ...
Ankit's user avatar
  • 1
-4 votes
1 answer
64 views

(C++17) efficient Text to Text compression for c++ using only standard libraries?

I want to compress data like this: 1 41 26 11 20 35 22 37 4 17 30 10 25 40 16 31 7 34 21 36 3 1 41 26 11 35 20 31 7 22 37 4 17 30 10 25 40 16 3 36 21 34 1 17 4 11 26 15 28 13 41 9 20 35 22 37 24 39 ...
Azruine's user avatar
  • 25
0 votes
0 answers
18 views

C++ code running using WSL Ubuntu, but not able to debug code in VS Code

I am trying to set up my VS code with WSL Ubuntu to run C++ code. I have installed gdb and g++ and able to run code using Ubuntu and VS code terminal. However, when I am trying to debug the code in VS ...
Sachin's user avatar
  • 1

1
2 3 4 5
215