Get path of executable
There is no cross platform way that I know. For Linux: pass “/proc/self/exe” to std::filesystem::canonical or readlink. Windows: pass NULL as the module handle to GetModuleFileName.
There is no cross platform way that I know. For Linux: pass “/proc/self/exe” to std::filesystem::canonical or readlink. Windows: pass NULL as the module handle to GetModuleFileName.
Put this in your CMakeLists.txt file (change any options from OFF to ON if you want): set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost 1.45.0 COMPONENTS *boost libraries here*) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) add_executable(progname file1.cxx file2.cxx) target_link_libraries(progname ${Boost_LIBRARIES}) endif() Obviously you need to put the libraries you want where I put *boost libraries here*. For example, if you’re … Read more
Boost Informational Macros. You need: BOOST_VERSION
For questions 1 & 2, I would recommend making a library from your non-test files excluding main.cpp (in this case just src/sqr.cpp and src/sqr.h), and then you can avoid listing (and more importantly re-compiling) all the sources twice. For question 3, these commands add a test called “MyTest” which invokes your executable “test” without any … Read more
Replaceable by C++11 language features or libraries Foreach → range-based for Functional/Forward → Perfect forwarding (with rvalue references, variadic templates and std::forward) In Place Factory, Typed In Place Factory → Perfect forwarding (at least for the documented use cases) Lambda → Lambda expression (in non-polymorphic cases) Local function → Lambda expression Min-Max → std::minmax, std::minmax_element … Read more
You can get the latest version of Boost by using Homebrew. brew install boost.
Basic properties of smart pointers It’s easy when you have properties that you can assign each smart pointer. There are three important properties. no ownership at all transfer of ownership share of ownership The first means that a smart pointer cannot delete the object, because it doesn’t own it. The second means that only one … Read more
Scope Boost.Asio is a C++ library that started with a focus on networking, but its asynchronous I/O capabilities have been extended to other resources. Additionally, with Boost.Asio being part of the Boost libraries, its scope is slightly narrowed to prevent duplication with other Boost libraries. For example, Boost.Asio will not provide a thread abstraction, as … Read more
This question has been discussed and answered by Scott, Andrei and Herb during Ask Us Anything session at C++ and Beyond 2011. Watch from 4:34 on shared_ptr performance and correctness. Shortly, there is no reason to pass by value, unless the goal is to share ownership of an object (eg. between different data structures, or … Read more
While Nate’s answer is pretty good already, I’m going to expand on it more specifically for Visual Studio 2010 as requested, and include information on compiling in the various optional components which requires external libraries. If you are using headers only libraries, then all you need to do is to unarchive the boost download and … Read more