I wrote an application using pthreads which had 5 threads. 4 of the threads filled up 4 buffers and once they had been filled the main thread would be combine these together. This was achieve using barrier so the main thread would wait until the 4 worker threads had reached the barrier. I am looking at re-writing this but using c++ 11 threads and see there isn't a barrier as such available and wanted to know what would be the best/safest way to achieve the same result as the pthread based program. Thanks in advance.

Member Avatar
Member Avatar
+0 forum 10

void assign(size_type n, **el const T& el = T()**) This function is a member function of the STL list class and I do not understand the bolded part. I understand the const T& el is a reference to a constant parameter which means I cannot change the value/content of the passed argument + I understand that el = T() means a default parameter so if there is no argument passed in the calling function the el will use the no-argument constructor of the T() type OK. But what make me confused the el at the beginning before the const?!!! so …

Member Avatar
+0 forum 0

**Okay this is my first post and I am quite excited that how it will be recieved by the community. I have a long experience in C++ programming but never been a part of any community hence I believe that as a tyro, my mistakes will be ignored.** This post will be about a problem statement that got in my college exams during my engineering. It was a question of an assignment. The question was as follows *Write the most efficient program to print Fibonacci series up to the value given during runtime and also store the values in a …

Member Avatar
Member Avatar
+0 forum 4

Hi all, I was just playing around with some ideas about optimizing a core piece of my library: the run-time type identification system (RTTI). What does that have to do with compile-time string concatenation? Well, the whole point of the RTTI is to provide information on the type of objects, and a string representation of that name is a pretty central part of that (as well as a hash value). Type names are made of identifiers, which are names that are known at compile-time, and could thus be compile-time string literals (that means things like `"Hello world!"`). The problem is, …

Member Avatar
Member Avatar
+6 forum 6

Hi! Have anybody seen Scot Meyers' video on Universal references? In order for a reference to be "universal" two requirements should be fulfilled : 1)variable should have double ampersand after it's type : sometype&& 2) the type should be deduced . The second point is somewhat confusing to me: despite examples provided there, Meyers hasn't given a clear definition : what does mean deduced type? So the question is : could you give if not a clear difinition of what criteria a type should fulfill in order to be called "deduced", but at least your vision on it. Thanks beforehand.

Member Avatar
Member Avatar
+0 forum 1

Creating WinAPI windows and controls can be a pain and quite difficult/annoying at times. Most of the time, I find myself searching MSDN, DaniWeb, and StackOverflow. I hate having to use external libraries unless I absolutely have no other choice. Below contains code for creating WinAPI windows, Controls, Sub-Classing, and EventHandling for each control. There is a sample working code below this article and an image of what the sample code produces. There are only 4 files to include to your projects: Form.hpp -- Form.cpp Controls.hpp -- Controls.cpp The code for these files are as follows: Form.hpp: #ifndef FORM_HPP_INCLUDED #define …

Member Avatar
Member Avatar
+0 forum 5

I found myself needing a threadsafe global variable to indicate when a thread is complete. Quickly discovered `std::atomic<type> var(val);` only to find it has no support in my IDE. Can anyone offer an alternative? I have an operation that needs to be carried out which takes some time, I cannot afford that time in current thread and want to subcontract the work to another thread. I'm going to be using global variable(s) (not sure if I can use static) to which the thread can deposit the result(s). And of course I need a safe way to know when the spawned …

Member Avatar
Member Avatar
+0 forum 3
Code Snippet Simple Trie Class

As the title says, it's a simple trie class written in C++11. The only operations implemented are insert, remove, and search (both prefix and exact matches). I sort of abandoned the test/debug process, and while I'm somewhat confident that there aren't any serious bugs, I can't guarantee it. Use this class at your own risk. ;)

Member Avatar
Member Avatar
+3 forum 4

The annoying use case is this: for (vector<int>::size_type i = 0; i < v.size(); i++) { cout << v[i] << ' '; if (i == v.size() - 1) { cout << endl; } } C++11 offers the `auto` keyword for initializer type deduction so that we can avoid verbose and ugly types like `vector<int>::size_type`. However, the naive attempt doesn't work: for (auto i = 0; i < v.size(); i++) { cout << v[i] << ' '; if (i == v.size() - 1) { cout << endl; } } The reason it doesn't work is because 0 doesn't match the type …

Member Avatar
+5 forum 0

I've needed to write sample code using conio.h over the years, but my compilers don't support all of it (most notable being clrscr() and gotoxy()). So I wrote a conio simulator class to help me. Not all of the conio.h functions are present, such as cgets() and cscanf(), because I haven't needed them. But the design is such that they can easily be added. It's based around an abstract IConio class that can be inherited from for specific implementations. The conio.h library is *very* platform specific, and I've included a Win32 implementation as I work primarily with Windows systems. POSIX …

Member Avatar
+2 forum 0

I'm currently making a DLL with a collection of code snippets that I find myself commonly using. I have made a search functin that checks if one string is inside of another string. I have also added a vector choice in the case that I want to search many strings. In the header: static DATAEDITING_API bool Contains(std::string target, std::string source); static DATAEDITING_API bool Contains(std::string target, std::vector<std::string> source); static DATAEDITING_API bool Contains(std::string target, std::string source, bool sensitive); static DATAEDITING_API bool Contains(std::string target, std::vector<std::string> source, bool sensitive); Now the problem is that the following code snippet always returns true. The Contains(std::string, std::string, …

Member Avatar
Member Avatar
+0 forum 4

Another quickie. This is a basic class for working with Windows path strings. It's based off of .NET's System.IO.Path class, but doesn't contain any API dependencies (and thus doesn't normalize the paths, it's all straight string handling). Methods that I've personally found to be useful are included. The class is specific to std::string so as to remain both simple and clean.

Member Avatar
Member Avatar
+0 forum 2

For those of you familiar with the latest C++ standard, what do you think of [uniform initialization](http://en.wikipedia.org/wiki/C%2B%2B11#Uniform_initialization)? Listening to folks like Herb Sutter, it seems like the intended purpose is to be completely pervasive, which obviously changes the look and feel of C++. Do you plan on using it everywhere possible? Only in places where narrowing conversions are problematic? Never at all because it's ugly? ;) This seems like the most potentially controversial new feature of the language. Personally, I'm still on the fence about it. On the one hand it seems ugly and awkward, and on the other there …

Member Avatar
Member Avatar
+0 forum 6

No bells and whistles, just a quickie millisecond timer showing an alternative to the far less portable clock_t method. A test main() is included, just define TEST_DRIVER as a macro or remove the conditional compilation at the end.

Member Avatar
Member Avatar
+0 forum 1

Dear all, I am certainly not an expert in C++ development but after some time, I had some code running and compiling for a bio-informatics tool. As always in Science, I changed my area of research of a while and when I came back to my tool, I had changed my computer (and my gcc version) in between. In the program, I run several threads that call a function. This is where the function run_es_pval is called (and where the error message takes place) for (int i = 0; i < threadNb; i++) { int start = i * datasetPerThread; …

Member Avatar
Member Avatar
+0 forum 2

Problem: Write a program that prompts the user to enter some number of 1, 2, 5, 10, 20, 50 and 100 dollar bills. Query the user separately for the number of each size dollar. I think I've completed the code pretty well but the last part of the question states: Modify your program to use an initializer list for the vector, and use a range-based for statement to traverse the vector. Note: These C++11 features are available in g++-4.6 and Visual Studio 2012, but may not be available on other compilers. I don't understand what the last part is asking. …

Member Avatar
Member Avatar
+0 forum 7

Hi all! This is a simple piece of code that I wrote about a year ago, in response to a question on Daniweb. I decided to infuse it with some C++11 magic, which led to a pretty sweet code snippet, full of neat little techniques you might want to use, not to mention that this class can actually be pretty handy to have. There are a few similar implementations out-there, but they all use a different approach, my main inspiration is the scope-guard technique. This is an implementation of a simple wrapper class template that allows a variable to be …

Member Avatar
Member Avatar
+3 forum 14

Hey, I have a set of types which are all arithmetic (have operators for addition, subtraction, multiplication, etc.). I want to aggregate any number of them into a single object, so I'm using the std::tuple class template and the <tuple> library (and Boost.Tuple for backward compatibility). My question is a bit of a shot in the dark: Has anyone heard or seen a tuple-like class template that implements all the arithmetic operators? For example, the std::tuple and boost::tuple classes both implement all the comparison operators which will only compile correctly if all the types contained in the tuple also have …

Member Avatar
Member Avatar
+0 forum 4

The End.