Category : c++11

I want to know what happens if we have a function parameter that is a reference to a const function as shown below. Version 1 int anotherFunc() { std::cout<<"inside anotherFunc"<<std::endl; return 5; } void func(decltype(anotherFunc) const &someFunction)//note the const here { std::cout<<"inside func"<<std::endl; std::cout<<someFunction()<<std::endl; } int main() { std::cout << "Hello World" << std::endl; func(anotherFunc); ..

Read more

I have two class that follow this manner to encapsulate threads inside a C++ object. class MyThreadClass { public: MyThreadClass() {/* empty */} virtual ~MyThreadClass() {/* empty */} /** Returns true if the thread was successfully started, false if there was an error starting the thread */ bool StartInternalThread() { return (pthread_create(&_thread, NULL, InternalThreadEntryFunc, this) ..

Read more

Say I have a class which is a wrapper around stl::list and I want to be able to use range looping: #include <list> using std::list; template <typename T> class list_wrapper { public: list<T> _list; typename list<T>::const_iterator begin() { return l.begin(); } typename list<T>::const_iterator end() { return l.end(); } typename list<T>::iterator begin() { return l.begin(); } ..

Read more

In a thread which has not ever called and would never call asio::io_context.run(), must I invoke post() or dispatch() to dispatch tasks to the thread which has called asio::io_context.run()? Is it safe to directly call asio::async_write() or asio::async_read() in a thread which has not ever called and would never call asio::io_context.run() to dispatch tasks to ..

Read more