boost

Macro-based counter

狂风中的少年 提交于 2021-02-19 07:43:25
问题 Is it possible to create compile time constants like this: // event.h #define REGISTER_EVENT_TYPE() ... // Returns last_returned_number+1 // header1 #define SOME_EVENT REGISTER_EVENT_TYPE() // header2 #define SOME_OTHER_EVENT REGISTER_EVENT_TYPE() Where SOME_EVENT will be 0 and SOME_OTHER_EVENT will be 1. Tried the following code: #define DEF_X(x) const int x = BOOST_PP_COUNTER; #define REGISTER_EVENT_TYPE(x) BOOST_PP_UPDATE_COUNTER()DEF_X(x) #include REGISTER_EVENT_TYPE(SOME_EVENT_TYPE) But

Boost:spirit Parsing into structure and reusing parts of it

对着背影说爱祢 提交于 2021-02-19 07:38:23
问题 I have to find variables in a sentence and replace them by their value. Variables can be written in different forms, like $varName, or $(varName) for example. I'd like to have a struct VariableHolder to have easy access to both : struct VariableHolder { string name; // contains "varName" string fromFile; // contains "$(varName)" or "$varName" void setName(ustring n) { name = n; } } Obviously, I'd like to avoid doing multiple passes and calling multiple parsers. What I have so far is this :

CMake - Could NOT find Boost (missing: serialization) (found version “1.73.0”

自古美人都是妖i 提交于 2021-02-19 05:35:46
问题 I've been using Boost with my project for a while now, though until now, I'd only used the header-only libraries. I now want to use serialization, but when I try to add serialization as a REQUIRED component, I get the error written in the title. Here is my CMAKE file: cmake_minimum_required(VERSION 3.15) project(GinRummyCPP) SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/Program Files/boost/boost_1_73_0") SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/Program Files/boost/boost_1_73_0/libs

How to reproduce deadlock hinted to by Boost process documentation?

会有一股神秘感。 提交于 2021-02-18 22:31:33
问题 According to the Boost documentation (section 'Why does the pipe not close?'), the following code will result in a deadlock: #include <boost/process.hpp> #include <iostream> namespace bp = ::boost::process; int main(void) { bp::ipstream is; bp::child c("ls", bp::std_out > is); std::string line; while (std::getline(is, line)) { std::cout << line << "\n"; } return 0; } The documentation says: This will also deadlock, because the pipe does not close when the subprocess exits. So the ipstream

How do I create a file with boost filesystem without opening it

天涯浪子 提交于 2021-02-18 21:54:05
问题 In boost filesystem there is a function create_directory which creates a directory. How do I create a file? I could create one by defining a boost::filesystem::ofstream object but that would also open the file, so I would have to call close on it before I could do other stuff to it, like renaming or deleting. Is this the only way? 回答1: Boost Filesystem V3 doesn't provide a touch(1) function; Even touch will creat+close a file, just look at the output of strace : open("/tmp/q", O_WRONLY|O

why must a Boost.Asio handler be copy constructible?

夙愿已清 提交于 2021-02-18 20:51:52
问题 According to http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/Handler.html, a handler provided to io_service::post must be copy constructible. However, this excludes a scenario where a socket is accepted, and the response handler is moved, guaranteeing me that there is only one handler for the job: auto socket = std::make_unique<socket>(); accepter.accept(*socket); service.post([s{std::move(socket)}] { asio::write(*s, buffer("response"), ignored_err); }); So why is this copy

Spirit X3, How to get attribute type to match rule type?

為{幸葍}努か 提交于 2021-02-18 17:50:53
问题 For the development of Spirit X3 parser I want to use semantic actions(footnote 1). It is important for me to be in control of how to store attributes into STL containers. This question is about how to control that the parser attribute: _attr( ctx ) match the rule type: _val( ctx ) so that it can be assigned properly. Maybe this question boils down to how to apply the undocumented transform_attribute feature. But please read with me to see if that is actually the thing that solves it for me

Step/Stride Iterator for use with std::minmax_element

孤街浪徒 提交于 2021-02-18 16:56:31
问题 I have a 1D float array which represents a m *n (rows and columns) table of float values. My requirement is to find a min/max element for each row and column. For rows I can easily do it by using std::minmax_element by specifying a range of n elements. But for columns I need to use a stride iterator as elements are placed are not contiguous but placed at a step interval of n. Is there a standard iterator in boost/STL that can be used. The other option is to write my own version of it. What is

Step/Stride Iterator for use with std::minmax_element

只愿长相守 提交于 2021-02-18 16:56:24
问题 I have a 1D float array which represents a m *n (rows and columns) table of float values. My requirement is to find a min/max element for each row and column. For rows I can easily do it by using std::minmax_element by specifying a range of n elements. But for columns I need to use a stride iterator as elements are placed are not contiguous but placed at a step interval of n. Is there a standard iterator in boost/STL that can be used. The other option is to write my own version of it. What is

cannot find boost_process cmake find_package

跟風遠走 提交于 2021-02-18 11:17:05
问题 I'm trying to import boost libraries into my C++ project, and for some reason it cannot find Boost.Process, although it finds the others. My CMakeLists.txt file: cmake_minimum_required(VERSION 3.9 FATAL_ERROR) set (PROJECT_NAME "test-stuff" CXX) project (${PROJECT_NAME}) set(Boost_USE_MULTITHREADED ON) find_package(Boost 1.64.0 REQUIRED system filesystem process) if(Boost_FOUND) include_directories (SYSTEM ${Boost_INCLUDE_DIR}) endif() include_directories(include) file(GLOB SOURCES "src/*.cpp