Skip to main content
Filter by
Sorted by
Tagged with
2 votes
4 answers
237 views

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 ...
GhostVaibhav's user avatar
1 vote
4 answers
119 views

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 ...
kalj's user avatar
  • 1,502
3 votes
5 answers
294 views

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 ...
Nick Reed's user avatar
  • 5,109
-3 votes
2 answers
183 views

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 ...
Igor's user avatar
  • 6,473
0 votes
0 answers
46 views

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(...
DaNilsoN's user avatar
0 votes
0 answers
58 views

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 ...
v.oddou's user avatar
  • 6,867
2 votes
4 answers
198 views

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 ...
gene b.'s user avatar
  • 12.6k
0 votes
4 answers
269 views

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 ...
BalmyWinner's user avatar
0 votes
1 answer
118 views

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;}; ...
vazlsky's user avatar
  • 2,360
0 votes
4 answers
202 views

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 ...
Marcus Hampel's user avatar
4 votes
2 answers
130 views

I have two types, CustomNotCompatibleWithRun, CustomCompatibleWithRun, and a run() function: #include <iostream> #include <type_traits> template <typename T_> struct ...
zhanginou's user avatar
  • 327
-1 votes
3 answers
183 views

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 ...
Artur Brodsky's user avatar
5 votes
1 answer
63 views

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> ...
DrDreadful's user avatar
3 votes
1 answer
121 views

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 ...
Questor's user avatar
  • 314
5 votes
1 answer
233 views

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; ...
Fedor's user avatar
  • 24.7k
4 votes
1 answer
97 views

In C++, you can inherit all constructors of a base class by writing using Baseclass::Baseclass My Baseclass has both a default constructor and another one that takes an int argument, even though that ...
DRman's user avatar
  • 41
3 votes
2 answers
100 views

Is it possible to allow a universal reference argument to be only called as const lvalue-ref or rvalue-ref, but not lvalue-ref? Consider this: #include <string> #include <iostream> struct ...
user3612643's user avatar
  • 6,030
3 votes
2 answers
146 views

I have a function that returns a value from an internal optional. T foo() { std::optional<T> v; ... return *v; } What's the most efficient way to return *v? return *v return *std::move(v)...
user3612643's user avatar
  • 6,030
2 votes
1 answer
143 views

The following not very long program is treated differently by the current compilers: class A { protected: operator auto(); }; template<class> struct B : A { using A::operator auto; }; ...
Fedor's user avatar
  • 24.7k
0 votes
1 answer
51 views

I am creating a binary tree representation of a mathematical expression for performing differentaiton and integration on it. I am trying to overload the + operator for my Symbol class. It works fine ...
Aditya Vinchhi's user avatar
1 vote
4 answers
225 views

I need to access an std::array<double, 9> x by two functions, namely funA and funB. funA only needs the first 6 entries of x and funB the last 3 entries. I am limited to C++14. I know there are ...
Fredo's user avatar
  • 47
0 votes
0 answers
122 views

I've read in Stroustrup PPP "Programming Principles and Practice Using C++", 2nd edition in table "useful operators for some common and useful types" here that type "char&...
fedya's user avatar
  • 19
0 votes
0 answers
120 views

Am i allowed to do this safely, assuming func is only ever called with &container_instance.bar? struct foo_t { int val; }; struct bar_t { int val; }; struct container { foo_t foo; bar_t ...
IAmPropper's user avatar
0 votes
0 answers
49 views

I read the book "C++ Concurrency in Action, 2nd Edition" (from Anthony Williams), and I'm not sure of one sentence in appendix A.4.1 : "But that's about all you can do in C++11 - a ...
kingsjester's user avatar
1 vote
1 answer
77 views

Please have a look at this more or less standard example that i see people use when talking about the usage of volatile in the context of embedded c++ firmware development on a baremetal target: // ...
IAmPropper's user avatar
1 vote
1 answer
108 views

cppreference says that, until C++14, a constexpr function must satisfy the following requirement: the function body must be either deleted or defaulted or contain only the following: null statements ...
Alex O's user avatar
  • 1,976
0 votes
2 answers
108 views

Is there a way to get ride of the tmp and the second call to std::snprintf in Print? Can I do the same with just one std::snprintf call? // arm-none-eabi-g++ -std=c++14 -O3 -Wall -fno-rtti -fno-...
ge45mue's user avatar
  • 715
2 votes
1 answer
143 views

Clang accepts accessing data-member d from within alias template p, whereas GCC and MSVC reject it. Should this be allowed or not? What does the standard have to say about it? When accessing d ...
303's user avatar
  • 4,852
0 votes
0 answers
38 views

I'm trying to write a specialized constructor that would accept integer argument and converted it to enum. My attempt is below, but it fails with an error. Other template candidates are rejected, and ...
nd65's user avatar
  • 1
3 votes
1 answer
198 views

I'm currently downporting C++17 code to C++14. Since C++14 doesn't have variant I'm using the variant implementation by mapbox which is available here. Basically, substituting variant using mapbox::...
Andreas's user avatar
  • 10.5k
4 votes
2 answers
92 views

Is it possible in C++14 (so no constraints, require or fold expressions, but there is SFINAE) to have a partial template specialization of a class template template <typename ...T> class Generic ...
Daniel Varga's user avatar
0 votes
1 answer
212 views

I'm trying to port a C++17 project to an exotic platform that doesn't have anything newer than C++14. The C++17 project I'm trying to port to C++14 uses a lot of calls to is_XXX_v functions, e.g. ...
Andreas's user avatar
  • 10.5k
0 votes
0 answers
76 views

I'm getting a segfault - Python exit code 139 (11:SIGSEGV) - when attempting to access a struct member variable. The struct looks like: struct PlannerResult { std::vector<Node> route; double ...
Carl's user avatar
  • 11
1 vote
1 answer
124 views

I'm confused with this statement on Relaxed ordering Even with relaxed memory model, out-of-thin-air values are not allowed to circularly depend on their own computations, for example, with x and y ...
zzzxyz's user avatar
  • 13
1 vote
3 answers
155 views

I want to have 2 method, one is SetVariable and the other GetVariable in MyClass both will receive an enum and arguments, the arguments can be more then one and more then one type and according to the ...
MBDarkstrike's user avatar
2 votes
2 answers
99 views

I have a problem understanding why the following code fails to compile: #include <iostream> #include <vector> #include <type_traits> enum class Error { OK = 0, NOK = 1 }; ...
Daniel's user avatar
  • 93
2 votes
1 answer
162 views

Note that I am not asking "When do function templates get instantiated?" Rather, "When are the side-effects of that instantiation visible?" An example of a side-effect of an ...
Joshua Maiche's user avatar
1 vote
2 answers
85 views

I have a std::map<K, T, std::less<>> and a “key” of type KK which is order-compatible with K. If the key is present, I want to return the corresponding value. If the key is not present, I ...
Bolpat's user avatar
  • 1,775
0 votes
2 answers
110 views

I'm looking for a log2(N) way of searching a std::vector and receive a RandomAccessIterator. I want it to work exactly as std::lower_bound() but return a RandomAccessIterator instead of a ...
user1804394's user avatar
0 votes
1 answer
155 views

I was trying to create a bidirectional tree-like structure, so Ive ended up with the following struct`s: template<typename T> struct Node { T value; std::vector<...
Anton Grant's user avatar
14 votes
3 answers
2k views

In the question Idiom for initializing an std::array using a generator function taking the index?,which basically asks how one can initialize an array of an arbitrary type which is not necessarily ...
Weijun Zhou's user avatar
  • 5,569
0 votes
0 answers
61 views

std::array<T,N>::operator[] always returns an lvalue reference (const if needed), but what can possibly be the use of a line of code like this, which is valid C++? std::array<int,1>{1}[0] =...
Enlico's user avatar
  • 30.3k
0 votes
0 answers
78 views

In my company we try to create packages of gRPC and all dependencies in our private conan repository. Currently we stuck with gcc6.4.0 and VS2017. I had currently created packages for these ...
nablit's user avatar
  • 1
2 votes
3 answers
264 views

I'm new to learning modern C++ programming. I have read many blogs and questions but haven't found the answer of this question. In C++, compared to final or not virtual function, what is the advantage ...
CatFood's user avatar
  • 165
1 vote
2 answers
125 views

I'm trying to implement a class template with static member functions that can handle different types. My code looks like this (very simplified example): #include <array> struct Foo { ...
user3612643's user avatar
  • 6,030
5 votes
1 answer
396 views

I have the following code that compiles fine on GCC 13.2. Colleagues can't compile it on GCC 13.1. The new version compiles fine even with -Wall -Wextra. I assume that GCC 13.2 is better and more ...
Thomas Weller's user avatar
6 votes
4 answers
255 views

I'm trying to understand whether it's valid to call std::free() on the result of placement new in a buffer allocated by std::malloc(). Consider the following. Does this code exhibit any undefined ...
Noam Elul's user avatar
  • 686
0 votes
0 answers
87 views

I have added all the dependencies but after adding it i am getting some linking error. I am using visual studio 2015 buildtool v140 , platform v8.1 and platform win32. I have added the necessary ...
Lalit Sharma's user avatar
1 vote
1 answer
114 views

I am implementing a log function which logs along with line number of the code. The snippet of the code as follows: #include <iostream> using namespace std; char m_buffer[500]; template<...
GShaik's user avatar
  • 311
0 votes
2 answers
121 views

I was using an alias to refer to one of two maps: map<int, int> & map_alias = use_map_a ? map_a : map_b; but then changed map_b to use std::greater as its comparator (instead of the default ...
Gymkata's user avatar
  • 57

1
2 3 4 5
172