Questions tagged [c++11]

C++11 is the name of the C++ standard, approved in 2011. It replaces the previous C++03 standard, adding various core language changes and fixes, and an improved and expanded standard library.

Filter by
Sorted by
Tagged with
0 votes
2 answers
90 views

What is the minimum now() functionality required for std::chrono clocks [closed]

I would like to use std::chrono::time_point in some simulation software I am writing. I would like to take advantage of features like the time point arithmetic functions. However, I run into a snag. ...
Cort Ammon's user avatar
  • 10.9k
0 votes
2 answers
118 views

Modular Design affects compilation time

Does modular design decrease compilation time in cpp? My professor said so, but I don't understand how, because the build and compilation time depend on the amount of code, right? Also, wouldn't ...
happy's user avatar
  • 11
-1 votes
2 answers
738 views

Is TC++PL 4th Edition by Bjarne Stroustrup outdated?

First of all, I hope this question doesn't fall under "Asking For Books Recommendation" Category. Since TC++PL covers C++11, it is 3 revisions old (C++14, C++17, C++20), the ISO group is ...
theasker's user avatar
1 vote
1 answer
990 views

How does a blocking call work?

Effective Modern C++ recommends using void futures as a way to communicate one-off events from one thread to another. Below is a minimal reproduction of that practice. std::promise<void> promise;...
msmoiz's user avatar
  • 21
0 votes
1 answer
48 views

Dynamically discovering field usages for validation

Thanks for reading my question. I have a class which reads a configuration and based on the configuration, populates a data structure by reading from a database, which is ultimately presented to a ...
Sampath's user avatar
  • 119
0 votes
0 answers
60 views

Modular design of authentication schemes for a http client

I want to make a httpClient wrapper that is able to use a predefined set of authentification methods: basic, digest, token (oauth), ntlm just to name a few that I will have to implement. My approach ...
niraami's user avatar
  • 109
1 vote
3 answers
545 views

What is the best object-oriented design approach for a tree with two node types?

I have a tree-like structure as shown in below picture (as one small example). The tree consists of two different node types, that are: Data Nodes: These nodes that are colored in yellow contain ...
TonySalimi's user avatar
0 votes
2 answers
259 views

Worker pool running tasks of the same kind serially

I would like to run tasks in parallel. At this time, I am using a very simple worker pool using a single concurrent queue shared by all the threads. Every task has a non unique "tag" (an integer in ...
Willie Taylor's user avatar
2 votes
1 answer
273 views

Why did C++11 add find_if() instead of overloading find()?

Why did c++11 add a separate find_if() instead of simply overloading the existing find()? Wouldn't overloading the function be sufficient?
Jankovsky144's user avatar
4 votes
1 answer
120 views

Coupling and shared entity classes

I am currently working on a problem that has a central controller that is handling inputs and outputs between various modules and maintaining a number of entity classes as these change. When working ...
zachsmthsn's user avatar
2 votes
2 answers
293 views

Introduce code standard into old code

Our main product is written in C++ MFC and follows the same code standard as MFC. Now we will start to develop new components, and think about whether we should continue to use the same outdated ...
magol's user avatar
  • 201
2 votes
0 answers
1k views

multithreading - waiting on a condition without using locks (c++11)

i've been wondering about it for a while now but never found any answers. is it possible to use something like a condition variable without a lock? I have a vector of objects, and a thread pool, and ...
Alon Hershkovitz's user avatar
0 votes
1 answer
208 views

What OOP design pattern would work best for an overseeing class connecting related objects enforced at compile-time?

The Problem I would like to create a managing "overseer" class that connects several related object groups together where any particular group is able to be easily swapped for another using ...
Alex's user avatar
  • 9
0 votes
1 answer
229 views

Re-usability in C++ using Interfaces and External Configuration

I am practicing professional C++ by building a differential drive robot that applies a Go-To-Goal Behavior. What is I have written so far is an Agent that consumes the following interfaces: ...
Sam Hammamy's user avatar
0 votes
1 answer
106 views

Multithreading - 2 active running threads calling each other without blocking itself

I have an implemented UDP receiver which is continuously receiving DTN packets (UDP encapsulated) and performing some operations on them. This whole process is working on a single main thread. However ...
Caspian's user avatar
  • 13
0 votes
1 answer
126 views

Class holding collection of other class

I have a class Item. Then another class ItemCollection holds std::map<int,Item> item_collection_. The reason to create the class ItemCollection is if I want to do something with collection of ...
pokche's user avatar
  • 223
2 votes
3 answers
989 views

What is late binding?

I know, there are lots of sources on the internet, but I do not understand them. Wikipedia: "Late binding, dynamic binding, or dynamic linkage is a computer programming mechanism in which the method ...
Jaroslav Tavgen's user avatar
0 votes
0 answers
181 views

Base class with bool flag to imitate virtual constructor

I am using bool flag to call base class function when needed to imitate virtual constructor. I am using this way for inheritance purpose. I have a Base class constructor with int and bool. The bool ...
pokche's user avatar
  • 223
0 votes
1 answer
183 views

Avoid numerous dynamic_cast_ptr in the API design of polymorphic types

I am trying to design a geometric intersection API. Below is the code to represent geometric elements. #include <iostream> #include <memory> // Since I did not write the Shape class I ...
solti's user avatar
  • 369
1 vote
0 answers
66 views

How to specify constant data wrt cache coherence?

I am suspecting cache latency issues due to constant data (or same data across multiprocessor caches) being churned up in the cache coherence protocols. Is there a way to specify specific data as ...
RE60K's user avatar
  • 267
0 votes
1 answer
586 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
Late347's user avatar
7 votes
4 answers
4k views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
CK.'s user avatar
  • 187
-1 votes
1 answer
2k views

Combining the arguments of a function using a single structure

What are the consequences (pros and cons) of using a single structure as the argument, instead of a list of parameters. Some of the advantages I see are: create multiple default parameters. Need not ...
Soo's user avatar
  • 107
5 votes
2 answers
2k views

Implementing reference counting from scratch or using shared_ptr for resource?

In an OpenGL application that I am writing, I want to have a simple shader class to wrap the OpenGL shader handle. Ultimately, I want this shader class to behave very similarly to a shared_ptr in c++ (...
Anonymous Person's user avatar
31 votes
5 answers
31k views

Is passing arguments as const references premature optimization?

"Premature optimization is the root of all evil" I think this we can all agree upon. And I try very hard to avoid doing that. But recently I have been wondering about the practice of passing ...
CharonX's user avatar
  • 1,633
0 votes
1 answer
873 views

Advantage or disadvantage of using = operator or uniform initializer while using auto keyword

Most examples of auto use the = operator. #include <iostream> int main() { auto a = 1; std::cout << a << '\n'; } Why don't they use the uniform initializer like this? #...
Lone Learner's user avatar
5 votes
2 answers
5k views

'Assigning' a base class to a derived class?

I'm looking through some legacy code and I've come across a case where the developer has 'extended' an existing class with additional members, using inheritance as his weapon of choice. Essentially it ...
WalderFrey's user avatar
1 vote
1 answer
129 views

Should repeatedly-computed quantities derived from member data be stored in member data containers?

This question is generally regarding when it is a good idea to store quantities derived from member data in, say, std::vectors that will be repeatedly computed/accessed in various methods, but I will ...
AnInquiringMind's user avatar
12 votes
4 answers
19k views

Using vectors of shared pointers to objects in my C++ code to prevent object duplication

In my C++ project, I have three classes, Particle, Contact, and Network. The Network class will have N particles (std::vector<Particle> particles) and Nc contacts (std::vector<Contact> ...
AnInquiringMind's user avatar
6 votes
1 answer
500 views

"The C++ Programming Language" confusion on Comparison

I am not grasping the idea from this quote by Stroustrup on page 862 of "The C++ Programming Language" 4th edition at the end of the first paragraph (I've highlighted the relevant portion): ...
lostdong12's user avatar
5 votes
2 answers
16k views

How to pass a mock as std::unique_ptr to Class under test

I am writing some test units using googletest and googlemock and I am stuck in a problem related to C++11 smart pointers and polymorphism. Suppose you have those classes: class A { public: ...
Marco Stramezzi's user avatar
6 votes
2 answers
889 views

What Design to choose for Parsing different files to populate different classes?

I am currently working on project which requires parsing different types of files. The content of the files will populate the classes. eg: file1 populate content of class1, file2 populate content ...
vanta mula's user avatar
2 votes
1 answer
95 views

Does an explicit temporary of an integral type qualify as an integral constant expression?

In the following code, int() is an explicit type conversion. #include <iostream> int main() { void* ptr = int(); return 0; } Clang Compiler: source_file.cpp:5:11: error: cannot ...
Jemes's user avatar
  • 133
2 votes
4 answers
2k views

Refactoring large code base legacy C++ project that mixed with C style

Background: Currently I am working on a C++ project. It's for business use, so this project is not open sourced. However, this is a project with a fairly large code base (around 10k lines of code) ...
RandomEli's user avatar
  • 141
1 vote
0 answers
453 views

Constructing a stateful allocator using an interface

I have the following abstract class which implements the "Allocator" concept, using policies and traits to customize behavior: #define FORWARD_ALLOCATOR_TRAITS(C) \ typedef ...
MattyZ's user avatar
  • 113
0 votes
1 answer
163 views

Function returning different tuples [closed]

I am trying to learn C++11/14 new features and I am playing with tuple and variadic. I wonder if it is possible to use tuples to return multiple values that are not fixed at compile time. Something ...
Marco Stramezzi's user avatar
1 vote
5 answers
2k views

Handling errors for non-exceptional cases in modern C++

To hone my skills - and for the pleasure of it - I am writing a small game for my kids in modern C++ (C++11, C++14 and the part of C++17 already supported by Visual Studio), which is a nice break from ...
Francesco's user avatar
  • 1,426
0 votes
1 answer
149 views

System design for a client server problem

I am trying to design and implement a solution for the following problem I am facing in one of my projects. There are n (say 30) clients that send me data points of the form {timestamp, object}, ...
zorro's user avatar
  • 1
3 votes
1 answer
3k views

List initialization by empty braced-init-list (value-initialization or by initializer_list) vs explicit default initialization, for "list" types

Background Based on Item 4 in Scott Mayers Effective C++, when appropriate, it can be good practice to initialize all member properties of custom types via the member initialization list (in same ...
dfrib's user avatar
  • 201
3 votes
1 answer
169 views

What should I use for technically always read-only objects?

I have a function get() which gets a human object from somewhere. That is literally the only use of human, to provide a collection of properties of a human. struct human { std::string first_name; ...
Rakete1111's user avatar
16 votes
3 answers
28k views

Is there any benefit to to define constant local variables as static ( c++)?

void Animation::playAnimation() const { static const int index = 0; const std::string& animationFileName = m_animationContainer.getAnimationName(index); static const int zOrder = -...
T M's user avatar
  • 279
-5 votes
2 answers
2k views

recommend a design pattern for a C++ application that takes some data, processes it, and returns results

So I am new to design patterns and C++11, but I have been studying both quite a bit. I am working on developing a C++ application to process some data, and I was hoping that someone with more ...
krishnab's user avatar
  • 179
33 votes
2 answers
12k views

Is it ever bad to mark a C++ function constexpr?

Given a very trivial function, int transform(int val) { return (val + 7) / 8; } It should be very obvious that it's easy to turn this function into a constexpr function, allowing me to use it ...
Xirema's user avatar
  • 513
1 vote
1 answer
80 views

Handling more specialized interface with no code duplication

I have the following code: struct AInterface { XXX some_method(/* some params */) = 0; }; void foo(const AInterface & a) { do_work(); while (x) { do_work_2(); ...
Svalorzen's user avatar
  • 467
8 votes
1 answer
549 views

Do C++'s iterator categories forbid writing a UTF-8 iterator adapter?

I've been working on a UTF-8 iterator adapter. By which, I mean an adapter that turns an iterator to a char or unsigned char sequence into an iterator to a char32_t sequence. My work here was inspired ...
Nicol Bolas's user avatar
  • 11.9k
5 votes
1 answer
10k views

Why is accessing virtual protected functions of a base class not allowed through a pointer of the base class type inside a derived class

Consider the following: #include <iostream> class Base { public: void go(){this->doSomething();} protected: virtual void doSomething(){std::cout << "base";} }...
Andy Forrest's user avatar
5 votes
1 answer
203 views

Appropriate use of mediator pattern

I'm writing a program that has one class called Driver, which reads audio, sends it through an effects chain and then sends it to an audio output. The effects are created from dynamic libraries (using ...
tay10r's user avatar
  • 205
10 votes
2 answers
3k views

Is this a good approach for a "pImpl"-based class hierarchy in C++?

I have a class hierarchy for which I would like to separate the interface from the implementation. My solution is to have two hierarchies: a handle class hierarchy for the interface and a non-public ...
Steve Emmerson's user avatar
8 votes
3 answers
7k views

Are all the objects in C++ mutable if not stated otherwise?

Is every object in C++ mutable if not stated otherwise? In Python and Javascript I can't change strings, tuple, unicodes. I was wondering if there is something in C++ that is immutable or every ...
G M's user avatar
  • 257
0 votes
3 answers
314 views

How to represent personality of a person in class?

Lets say I have a class Person. class Person{ Person(std::string, int); void walk(); void talk(); void eat(); private: int age; std::string() name; }; Now lets say I want ...
solti's user avatar
  • 369