Hot answers tagged

14 votes
Accepted

Porting C-style socket to CPP class

Avoid using malloc() in C++ There are much better ways to allocate memory in C++ that are simpler and safer. First, in C++ you should use ...
user avatar
  • 34.7k
6 votes
Accepted

C++ wrapper to call Python code

I can't answer your questions about your portfolio. It would be best to talk with a professor or student advisor about it, as this will be specific for the school or university you are at. That said, ...
user avatar
  • 34.7k
3 votes

Leetcode 14. Longest Common Prefix beats only ~50% of C++ solutions

Improve cache usage I agree with G. Sliepen that changing the order of iterating over strings may improve execution time. Consider the variant of the classic example as an illustration. ...
user avatar
  • 96
3 votes
Accepted

Leetcode 14. Longest Common Prefix beats only ~50% of C++ solutions

Precalculate the size of the shortest string In the inner loop you are checking str.size() < i. Consider that the longest common prefix cannot be longer than the ...
user avatar
  • 34.7k
3 votes
Accepted

Input validation of a signed double (in C++)

Not a bad first attempt for a beginner, though you probably bit off more than you should have for a first attempt. As @JerryCoffin suggested, it would probably have been enough just to validate the ...
user avatar
  • 8,536
3 votes

Hardware abstraction in C++ on STM32F4

I like the reg32_t type alias and the good use of binary literals. The static_assert()s are also a great way to prevent ...
user avatar
  • 34.7k
2 votes

Assignment function as alternative to std::tie

Honestly, it's useless. Unlike std::tie, this assign function only works when both the list of variables and the list of values ...
user avatar
  • 852
2 votes

2D grid container with arbitrary multiple data types

Use std::size_t The proper way to spell size_t is std::size_t. While often some library will ...
user avatar
  • 34.7k
2 votes
Accepted

A parse function for text line with fields separated by a comma with the known number and their type

Create a helper function To reduce the code repetition, a classic solution is to write a helper function. You can do that here as well. First let's look at how we want ...
user avatar
  • 34.7k
1 vote

C++ wrapper to call Python code

Do not cast C-string literals to char * If necessary, use const char * to avoid the risk of undefined behavior. Related question....
user avatar
  • 96
1 vote
Accepted

A periodic implementation for C++ using Grand Central Dispatch

TimerWorkLoop is useless The class TimerWorkLoop does almost nothing. It initializes mContext...
user avatar
  • 34.7k
1 vote

Input validation of a signed double (in C++)

Let the standard library validate the input for you The standard library does provide ways to parse a number from a string and to check whether the whole string was a valid number. Up to C++17, your ...
user avatar
  • 34.7k
1 vote

Input validation of a signed double (in C++)

I find this code rather difficult to follow. Right now, it seems to intermix code for determining whether a string constitutes a valid floating point value, with code for determining...other stuff you ...
user avatar
  • 33.2k
1 vote

Discussing approaches for converting Enum to String

Another way to solve this problem is by using X macros. These allow you to define the list of enum names and their values exactly once, and then create both the enum...
user avatar
  • 34.7k
1 vote

A PImpl helper class using type erasure

Avoiding the need for create() Is there any way to make that static FwdDecld create() function just be the default constructor? ...
user avatar
  • 34.7k

Only top scored, non community-wiki answers of a minimum length are eligible