Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag.
11
votes
Better size aligning?
Firstly, given that you're using vector without namespace qualification (that is, not as std::vector), I assume you have a using namespace std; in this code. This is generally a bad idea, but especial …
6
votes
Function wrapper like std::function that uses "small buffer" allocation
Generally, I can't see any real problems, but there are a few things that I'm going to point out:
In the assignment operator, you use std::swap(storage, rhs.storage) and declare it as noexcept. This …
5
votes
begin() vs rbegin(): how can I avoid duplication?
Since begin() and rbegin() produce different (incompatible) types, the only way I could see of doing this would be to move the actual for_each into a template function.
template <typename Iterator>
v …
7
votes
Accepted
Parallel factorial algorithm using std::thread
Firstly, some issues with API usage. Using raw std::threads is generally not the way you want to go with this sort of thing: prefer to use std::async. This also means you don't need to pass in by refe …
3
votes
Searching through a huge set with threads
There are definitely some problems if you want to make this threaded. Firstly, access to m_searches is not protected in any way. Since this is a shared bit of memory, it would need to be protected by …
4
votes
Copy and bit-invert ints in an std::vector
You can utilize std::transform here (I'll assume C++11 for the lambda):
int main()
{
std::vector<uint8_t> first_list = {0x01, 0x10, 0x32, 0x1A};
std::vector<uint8_t> second;
std::transfo …
7
votes
Checking for a palindrome
I just wanted to chime in with the "lazy" (if not performant) way of doing this, using reverse iterators:
bool is_palindrome(const std::string& s)
{
return s == std::string(s.rbegin(), s.rend()); …
6
votes
Accepted
3D mathematical vector class
Your design is a little bit confusing. You define your class as a template class, but just about everything takes and returns a double. Generally, you should try and be consistent: will this class wor …
22
votes
Accepted
Summing values in a vector using threads
Firstly, it's a good first attempt at writing some threaded code. The major sticking point is that you're passing in an int & and returning void. Of course, std::thread will just run some code and won …
2
votes
Accepted
std::once_flag and std::call_once implementation
Firstly, I'm not 100% sure how closely you want to follow the standard, but this is missing a (potentially significant) piece: what to do if the selection function throws an exception. From cppreferen …
3
votes
C++ implementation of Java's floatToIntBits() and intBitsToFloat()
I can't really speak to the portability of such code, as I honestly have no experience with anything other than IEEE754. Since you are targeting C++11, I can suggest that you can replace your compile- …
3
votes
Harmonic partial sum calculator with multithreading
Generally, you should prefer to use std::async over naked use of threads. There are a few reasons for this: firstly, std::async can actually return a value (wrapped in a std::future), which means less …
4
votes
Accepted
Constructing a class from a line in a parameter file
The approach to doing this is two-fold. Firstly, you'll want to modify your classes to have a constructor taking an std::istringstream& as an argument. The second part will be to make a map of strings …
3
votes
Avoid duplicated += -= operator code
I actually quite like this pattern and use it relatively often. I'm not sure if there is something better than functors for this - if there is, I'm not really aware of it. That being said, with C++11, …
4
votes
Accepted
unique_ptr usage too unwieldy
Let me restate the problem, because it wasn't 100% clear to me from what you've written. I personally think you've left out a bit too much code. I'll state my assumptions of what is going on, but idea …