Questions tagged [c++17]

C++17 is the version of C++ after C++14. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++17

Filter by
Sorted by
Tagged with
0 votes
0 answers
11 views

How to resolve the problem when vector pop_back the rbegin iterator became invalidated?

I want to remove a certain value from a vector using the following code. void removeValue(int n, vector<int>& v) { for (auto it = v.rbegin(); it != v.rend(); ++it) { if (*it == n)...
Riki's user avatar
  • 3
0 votes
0 answers
32 views

CMake C++ & CUDA: How to manipulate the compile options property only for a submodule and only for CUDA?

For example, a CMake submodule S has some compile flags inherited from its parent's modules, like -std=C++14. But submodule S is a CUDA project that requires C++17. I removed this flag like the ...
max_xu's user avatar
  • 21
-4 votes
1 answer
72 views

Character Array Print in C++

Here is the code I am using. int j=0; char v[] = {'a','e','i','o','u'}; for(j=0;v[j]!='\0';j++) { cout << v[j] << "\n"; } The "...
DeatHerTZ's user avatar
0 votes
0 answers
26 views

SDL2 Creating weird stretched rectangle over regular window when rendering textures

Below is code from Lazy Foo' Productions SDL2 tutorial series. I copied it directly to test if this was a problem with my code or if it was something else. This code and my own, which should work as ...
Oliver Green's user avatar
0 votes
0 answers
91 views

`if constexpr` does't compile with `avr-g++ -std=c++17` [duplicate]

In a method in a class I'm working on I have template <typename T = int_fast16_t, uint8_t Bits = sizeof(T) * 8 - 2> struct FixedPointFraction { using value_type = T; constexpr static uint8_t ...
Petr's user avatar
  • 62.8k
0 votes
0 answers
49 views

How to apply a predicate function for all elements of array/string [closed]

I want to create universal function which returns true if predicate was okay for all chars in string. There is no syntax error, but expected result does not appear. bool checkByProperty(std::function&...
rxvxl's user avatar
  • 1
1 vote
0 answers
116 views

Is it safe to overload std::floor in C++17? [duplicate]

Important: question is about C++17, before std::floor became a template. Lets say there is a user-defined template: template<class Unit> class Pixels {}; Is it safe to overload std::floor for ...
hopeless-programmer's user avatar
0 votes
0 answers
38 views

Despite having clang 15.0.0, vscode on mac os 14.1.1 my code isnt compiling according to newer c++ versions [duplicate]

(base) sushi@sushi C++ % cd "/Users/sushi/C++/" && g++ hello.cpp -o hello && "/Users/sushi/C++/"hello hello.cpp:22:26: error: delegating constructors are permitted ...
Shravan Rajput's user avatar
-2 votes
1 answer
53 views

Problem : invalid use of incomplete type ‘class NPCVisitor’ (NPC_visitor.cpp, 4 string), invalid use of incomplete type ‘class BattleField’(25 string) [closed]

I tried to connect header files in different places where it seemed that this was not enough, it did not help.I found this error information: There are several common causes of errors in the ...
Aleksandr Dots's user avatar
1 vote
1 answer
60 views

How to implemented comparison/less operator for member method pointers?

From my reading, I understand that it is possible to compare some pointer types in C++ using either operator< or std::less. This is useful if, for example, a pointer is used as a key for a std::...
Patrick Wright's user avatar
0 votes
2 answers
114 views

C++ - "HARD" types

Is there a solution to force a type in case the type itself is an alias? Example: using my_type = uint32_t; void my_function(my_type type) { ... } In the example above, valid code is both A and B: A: ...
user82375897897928347's user avatar
0 votes
1 answer
31 views

Keyboard shortcut in console, input - output

I'm learning programming from Stroustrup's book "The programming. Principles and practice using C++" There was a problem with the file not being executed in Visual Studio 22 (checking for ...
Eldar R's user avatar
1 vote
0 answers
111 views

Is a way to know if a variable is a numeric literal or constexpr at compile time using type_traits? [duplicate]

I'm working with templates and compile-time checks, and I would like to know if there is a way to know at compile-time if a variable is a numeric literal: is_numeric_literal_v<10> // result: ...
Aitorhub's user avatar
-1 votes
0 answers
44 views

Include SDL2 in the project

I have an assignment to write a game in C++. One of the criteria is that it needs to compline and run on the schools computers. Those systems have OpenGL and GLUT installed. I want to use SDL2 instead....
Demir Ince's user avatar
1 vote
2 answers
104 views

Generate switch cases for each type in a tuple/parameter pack

I am trying to figure out how to use template "magic" to automatically generate a switch statement for each type in a tuple. Here is my example code: #include <string> enum class ...
Patrick Wright's user avatar
0 votes
1 answer
33 views

Error updating a file .csv using the library iostream

I'm trying to update the information from a file that is separating the data with ";" and "/", my problem is that when I execute the code, if(is.good) return false bring me an ...
Juan Montes Trujillo's user avatar
1 vote
3 answers
121 views

Minimizing Meyers' singleton overhead

Meyers singleton, s. t.: Foo& getSingleton() { static Foo singleton; return singleton; } Is known to be: Thread-safe. Have a branch(es?) inside. And it also happens to be the easiest ...
blonded04's user avatar
  • 351
1 vote
2 answers
90 views

Guaranteed alignment of adress allocated by new expression

I am compiling the code with gcc 11.4 with -m32 -std=c++20 on Linux alignof(max_align_t) == 16 __STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16 What is the guaranteed alignment that I should expect from new ...
Uriziels's user avatar
1 vote
0 answers
58 views

Looking for design pattern for flexibile generic serialization

I have a header-only library that provides three class (templates), namely an abstract DAGNode, struct DAGNode; using NodePtr = std::shared_ptr<DAGNode>; class DAGNode { public: virtual ~...
joergbrech's user avatar
  • 2,223
-1 votes
0 answers
34 views

The variable declaration of the "ctime" file cannot be found, /usr/include/c++/9/ctime:60:11: error: ‘::clock_t’ has not been declared

My project file includes a third-party library that can be compiled independently. However, when compiling the entire project file, there may be a problem where variable declarations in some files in ...
guangjuchang's user avatar
2 votes
2 answers
220 views

Safely check if signed multiplication would overflow in C++17

I'm looking for a convenient idiom to check if a multiplication of two signed integers (longs or long longs) would overflow in versions of C++ where signed arithmetic overflow is undefined behavior (C ...
user3188445's user avatar
  • 4,166
-2 votes
0 answers
45 views

Handling library of simple objects in c++ with members that are mutable when you have to put them all in a namespace and they modify data [duplicate]

So, I have code that looks something like this: //Printer.h (minus the header protection) namespace GasStation { class Printer { private: int m_num_paper; public: explicit Printer(int ...
Brad's user avatar
  • 2,267
0 votes
1 answer
78 views

Is there a way to catch errors from mixing meter_t and mile_t? [duplicate]

Can the compiler be made to flag type problems in the following code? typedef float meter_t; typedef float mile_t; meter_t alpha = 100; mile_t beta = 200; if (alpha == beta) // Should be flagged { ...
Christopher's user avatar
0 votes
0 answers
5 views

ffmpegVideo plugin cant play video

when i start to play my command. i see first frame of video and then getting an error which like cant find the "object". my projet is CMake C++ project. error message is this [INFO] gObject: ...
gfsa gagfg's user avatar
1 vote
1 answer
38 views

Embedded: How replace the interrupt vector call with a lambda (poiner to member) in C++17

At the moment I have a problem. I want to replace the interrupt vector target call for a peripheral driver. What works for now is this: namespace test { class PortDriver{ public: using ...
tunguskar's user avatar
0 votes
0 answers
13 views

Segmentation fault inside KeyFrame::GetImuPosition()

I was facing Segmentation fault while running ORB-Slam 3 integrated with my custom application. I tried to write core dump and check the back trace. From frame 5 of stack trace below, the issue seems ...
MsA's user avatar
  • 2,663
0 votes
0 answers
55 views

Unresolved external symbol error from generated protobuf C++ code on Windows

I am building a shared library (DLL) that includes Protobuf generated C++ code. Below is the example proto. Sample.proto message Request { float id = 1; float name = 2; } The protobuf C++ code ...
pree's user avatar
  • 2,297
0 votes
0 answers
15 views

QTextStream verify status

Using Qt 5.11 In a legacy project I found the following code. void parse(QTextStream& stream) { if (stream.status() != QTextStream::Status::ok) throw std::runtime_error("error"); ...
LarsA's user avatar
  • 605
2 votes
0 answers
26 views

alglib's lsfitcreatef() function throws error over arguments that seem correct

I am using alglib::lsfitcreatef() in C++ to do nonlinear least-square fitting. I copied sample code from the website, here. The main difference is that I am using a vector of data that gets computed ...
Unstable Andy's user avatar
3 votes
1 answer
140 views

DRY: C++11 enum class vs C enum

I have class like this: struct InsertResult{ enum class Status{ INSERTED , UPDATED_IN_PLACE , REPLACED , SKIP_INSERTED , ...
Nick's user avatar
  • 10.1k
-1 votes
0 answers
24 views

after using glm::scale to an object matrix, the object moves(using glm::translate) faster than the object which wasnt scaled

Im making a game using openGL for graphics and glm for math. I have to adjust a bounding box to the size of a model it belongs to. I decided to use glm::scale, but after scaling the bounding box, it ...
Trenbolone Acetat's user avatar
0 votes
1 answer
77 views

cppyy cling fails on class member initialization if =default constructor was declared

I am trying to use cppyy (installed with STDCXX=17 MAKE_NPROCS=32 pip install --verbose cppyy --no-binary=cppyy-cling) for an existing header-only library that declares =default constructor together ...
Gleb Sternharz's user avatar
2 votes
1 answer
76 views

Specialization of a template class using enable_if [duplicate]

I am trying to partially specialize a template class which belongs to an external library. The external code is basically as follows. template <typename T> struct MyStruct; I would like the ...
Burak's user avatar
  • 2,350
2 votes
1 answer
113 views

How to handle long paths using std::filesystem in c++17

On Windows I am trying to iterate and collect all the files in the directory, Also I want to handle long paths and thats why I've added long path prefix (L"\\?\"). but it crashes with c++17'...
BitKnight's user avatar
  • 171
1 vote
1 answer
93 views

Print typeids of types in template parameter list

I would like to define a function that prints the typeid names of types in its template parameter list. The function accepts no value parameters. So for example calling print<int>() should print ...
sanitizedUser's user avatar
-2 votes
1 answer
102 views

Template function iterating over its arguments

I have two template functions template <class T> T &func1(int param, const T &component) { return do_something<T>(param, component); } template <class T> T &func2(...
mexx's user avatar
  • 51
-1 votes
1 answer
67 views

MSVC compiler warning c4984

I'm trying to implement a DLL and offer some interfaces to a legacy VS2017 C++14 project which I cannot control. (Original Post). I want to use if constexpr expression in my header files, and found ...
Eric Qiang's user avatar
1 vote
2 answers
133 views

Check if a function argument value is thread-local

In C++, is it possible to check (preferably at compile time) if a function argument reference value is thread-local? E.g. void foo( int& bar ) { ... } I'd like to check/enforce that bar refer to ...
Underhill's user avatar
  • 422
3 votes
1 answer
109 views

Does std::byte constructor extract LSB or MSB from integer?

I'm struggling to understand the following line of code: if constexpr (std::is_same_v<T, bool>) { std::byte change = std::byte(static_cast<uint32_t>(in) << m_addr[1]); std::...
dandan13's user avatar
  • 109
-1 votes
2 answers
75 views

C++ - Deriving public functions from a parent class to use in main.cpp file

The ERROR I'm having is in the main.cpp file. It's telling me to make .getName() a public function; I believe it is. How can I get around this issue? My code is organized with two header files "...
Tyler Fortune's user avatar
0 votes
0 answers
34 views

How to design a template to satisfy either std::queue or std::priority_queue?

I want to design a template like template<typename T, typename QueueType = std::queue<std::shared_ptr<T>>> class ThreadSafeQueue {}; template<typename T> auto cmp = [](const T&...
f1msch's user avatar
  • 585
0 votes
0 answers
51 views

error: expected unqualified-id before ‘)’ when I compile a c++ project

I'm having this error when trying to compile a cpp hook project /root/lib-173/hook.cpp:14:77: error: expected constructor, destructor, or type conversion before ‘(’ token rcmp::hook_function<...
Adriano Kramer's user avatar
-3 votes
1 answer
123 views

How to get a class name plus function name but no args in c++ that is able to handle template function, c function, static function, etc? [duplicate]

Hi I know this is an old topic: how to get c++ function name. But I really did not see a satisfactory answer. I am using c++17 so c++20 feature does not apply to me. I need a solid way that is able to ...
Dachuan Huang's user avatar
0 votes
1 answer
50 views

Is it possible to recursively chip an Eigen Tensor based on the values specified in an array?

I am trying to create a wrapper around an Eigen::Tensor object in c++. The idea is to create a chipped view on a Tensor based on a provided array, which either specifies the row along which to chip or ...
Yes's user avatar
  • 331
0 votes
1 answer
95 views

Is it possible to expose a set of C++ functions from a shared library?

I have a shared library and a set of functions that i want to be exposed from that shared library. The functions are C++ functions i.e. they are not extern c. Someone suggested me to use namespace and ...
yashC's user avatar
  • 905
0 votes
1 answer
68 views

If C++17 and above guarantee that allocators must support overaligned types, does that mean we can avoid creating manually-aligned types?

Given a custom vector and using std::allocator for allocating, under C++17 and above do we still need to create an internal overaligned type OT using alignas, then allocate for OT, and ...
metamorphosis's user avatar
4 votes
2 answers
173 views

Compile-time string compression with C++17 and earlier

I have an application that uses strings with long chains of repeated characters. I want to add them to the binary in compressed/obfuscated form. I'm currently using a modified RLE algorithm for ...
Fred Helmers's user avatar
-2 votes
0 answers
83 views

C++: Attempted to reference a deleted function - unordered_map for int

I'm new to C++, and I'm trying to implement Dijkstra's algorithm with priority queue, finding the shortest path between source s and destination t. I code this mostly based on my Python experiences. ...
Toàn Trần's user avatar
-3 votes
2 answers
322 views

PNG-file with wrong colors because of SDL_RenderReadPixels! Or: Which SDL_PixelFormat does this function return?

In my TexturWrapper class I need a method to save the main-texture or a part of it to a PNG-file. IMG_SavePNG is just able to save a SDL_Surface to a file, not a SDL_Texture. The main-texture of my ...
Brainfog's user avatar
0 votes
0 answers
30 views

Why this line fails to compile only on MSVC but not on Clang or GCC? [duplicate]

I have an CI on GitHub Action which runs Windows Server 2022 with Visual Studio 2022. Also, I have in the same Action a matrix to run Clang (macOS) and GCC (Linux). On GCC and Clang it compiles fine. ...
Rodrigo's user avatar
  • 137

1
2 3 4 5
217