8,580 questions
2 votes
4 answers
237 views
Two pointers referencing the same memory location, possible to make null if we deallocate the space?
If two pointers are referencing the same memory location. Will it be possible to make one pointer null, if we deallocate that memory location? For example: #include <iostream> using namespace ...
1 vote
4 answers
119 views
Setting std::function callback in polymorphic type
We are trying to create a class for setting options that can be either float or int (in reality, there are several more types). We want to store options of any kind in a single list, so we have made a ...
3 votes
5 answers
294 views
Does unsequenced behavior repeat itself?
tl;dr I have a program that "works", but does so in part via unsequenced behavior. I recognize that code with unsequenced behavior can technically do anything - however, it has to do ...
-3 votes
2 answers
183 views
Deleting memory for containers
I have std::map of std::vector of raw pointers. According to Google AI, in order to clean it I should do: int main() { std::map<int, std::vector<MyObject*>> myMap; // Populate the ...
0 votes
0 answers
46 views
Does QStandardItemModel take ownership of items when using appendRow()?
In my Qt application, I'm dynamically creating QStandardItem objects and adding them to a QStandardItemModel using appendRow(): auto* item = new QStandardItem("text"); model->appendRow(...
0 votes
0 answers
58 views
Pass a variadic templated function taking universal references as pointer to a utility
I have a problem with an attempt at factorizing two utility functions, each calling a given "hardcoded" function, into one utility with a functor call instead. Meaning I have a factoring ...
2 votes
4 answers
198 views
A generic wrapper for C++ vector of structs operations: removal, find_if, etc
I'm using C++ 14. I find C++'s vector operations erase and remove verbose and confusing and want to write a simple generic wrapper to remove an element from a vector of structs if that element's value ...
0 votes
4 answers
268 views
Is it possible to extend a member function?
I am relatively new to C++ and would like to know if it is possible to do the following and if so, is there a better way to achieve the same or similar result more efficiently? Declare a struct/class ...
0 votes
1 answer
118 views
Dynamic list of arguments for a variadic function
I need to refactor the following code (simplified for clarity) : #include <iostream> // those structs cannot be changed struct Foo1 {int f;}; struct Foo2 {int g;}; struct Foo3 {int h;}; ...
0 votes
4 answers
202 views
Prevent single member element from copy or moving?
I'm using a single structure to store multiple parameters. I want to access these parameters via their element names, just like a normal structure. I also want to name the structure elements and ...
4 votes
2 answers
130 views
Type trait to check whether a function can compile with a given type
I have two types, CustomNotCompatibleWithRun, CustomCompatibleWithRun, and a run() function: #include <iostream> #include <type_traits> template <typename T_> struct ...
-1 votes
3 answers
183 views
Why, if constructing a shared_ptr from raw pointer, "main()" exits with some negative error code? [duplicate]
Just experimenting with shared_ptr to explore its functionalities. I'm constructing a new shared_ptr object using a raw pointer from other shared_ptr object. The following code is compiling and runs ...
5 votes
1 answer
63 views
Can a boost::sml state machine with policies be copied?
From https://boost-ext.github.io/sml/examples.html#deferprocess Modified to try and copy the fsm. #include <boost/sml.hpp> #include <cassert> #include <deque> #include <queue> ...
3 votes
1 answer
121 views
Template iterators of a specific value type
I am trying to create constructors for building a class, that can take iterators of anytype, as long as they are an iterator for a specific value_type. With a different handler for all iterators of ...
5 votes
1 answer
233 views
Can initialization of static constant be skipped by 'case' label?
I have a constant declared in one case of my switch statement: void foo( int& v ) { switch( v ) { case 0: static constexpr int c{ 0 }; break; case 1: v = c; ...