c++

Expand #includes to a text file for C++

泄露秘密 提交于 2021-02-19 05:23:35
问题 Is it possible to expand out #include lines of a c++ file, probably using the C preprocessor, such that I can read an extended file without #includes , but instead with the files that are #include d? To be concrete, if I have fileA.cpp: #include "fileB.H" int main() { //do whatever return(0); } fileB.H: #include "fileC.H" //Some lines of code fileC.H //Some other lines of code And output: //Some other lines of code //Some lines of code int main() { //do whatever return(0); } Essentially, copy

A container of std::function with polymorphic types as function arguments

我与影子孤独终老i 提交于 2021-02-19 05:22:17
问题 I would like to have "yet another" callback registration stuff. Different event types extending a common base event type will trigger associated callback functions. here is the initial draft or idea #include <functional> #include <iostream> #include <unordered_map> class BaseEvent { public: virtual ~BaseEvent() {} }; class DerivedEvent_1 : public BaseEvent {}; class DerivedEvent_2 : public BaseEvent {}; // a container holding callback functions std::unordered_map<size_t/*event*/, std:

Expand #includes to a text file for C++

ぐ巨炮叔叔 提交于 2021-02-19 05:19:06
问题 Is it possible to expand out #include lines of a c++ file, probably using the C preprocessor, such that I can read an extended file without #includes , but instead with the files that are #include d? To be concrete, if I have fileA.cpp: #include "fileB.H" int main() { //do whatever return(0); } fileB.H: #include "fileC.H" //Some lines of code fileC.H //Some other lines of code And output: //Some other lines of code //Some lines of code int main() { //do whatever return(0); } Essentially, copy

Pass a C++ member function to a C function

落爺英雄遲暮 提交于 2021-02-19 05:17:32
问题 We have a structure that accepts C function pointers: int one(int x) { } int two(int x) { } struct Cstruct { int (*fn1)(int); int (*fn2)(int); }; Now I have a C++ class that has below methods: class A { public: int one(int x) { } int two(int x) { } int three(int x) { struct Cstruct cstr = {&this->one, &this->two}; } }; While trying to initialize class A methods address to a instance of Cstruct compiler is giving error of an invalid conversion? How can I assign the Class member function

A variable template that is true iff a class template would instantiate?

醉酒当歌 提交于 2021-02-19 05:14:47
问题 Let's say I have a class template A that has one type template parameter, and a single primary specialization: template<typename T> struct A { /*...*/ }; For some T arguments A<T> will instantiate successfully, for others it won't. Without modifying or extending the definition of A , is it possible to write a bool variable template: template<typename T> constexpr bool WorksWithA = /*...*/; such that WorkWithA<T> is true iff A<T> would instantiate successfully? Update Posted this as separate

A variable template that is true iff a class template would instantiate?

安稳与你 提交于 2021-02-19 05:14:19
问题 Let's say I have a class template A that has one type template parameter, and a single primary specialization: template<typename T> struct A { /*...*/ }; For some T arguments A<T> will instantiate successfully, for others it won't. Without modifying or extending the definition of A , is it possible to write a bool variable template: template<typename T> constexpr bool WorksWithA = /*...*/; such that WorkWithA<T> is true iff A<T> would instantiate successfully? Update Posted this as separate

How to create a tuple of vectors of type deduced from a variadic template in C++17?

▼魔方 西西 提交于 2021-02-19 05:04:11
问题 I have implemented a collection class that converts a vector of tuples to a tuple of vectors (it is essentially an AOS to SOA conversion). This code works for this example of two template classes. I was trying to make it more generic by using variadic templates. In order to do that I need to create the type for the member variable m_col . In C++17, is it possible to convert a tuple to a tuple of vectors? So the type of the member variance m_col in this example will be generated automatically

C++ enum class: Cast to non existing entry

ⅰ亾dé卋堺 提交于 2021-02-19 04:52:35
问题 I have this situation on one Project where we have some socket-communication that mainly exchanges characters for flow-control. We cast those characters to an enum class : char in a switch. I was wondering, what might happen, if the other end sends an character that is not in our enum class. I have this mwe: enum class Foo : char { UNKNOWN, ENUM1 = 'A', ENUM2 = 'B', ENUM3 = 'C' }; char bar1() { return 'B'; } char bar2() { return 'D'; } int main() { switch((Foo)bar1()) { case Foo::UNKNOWN:std:

QT missing dll after deploy

霸气de小男生 提交于 2021-02-19 04:41:27
问题 I've copied all of the dlls from QT that were required, and my application works fine on my Windows server machine. However when trying to run it on a Windows 7 box i get the following message: This application failed to start because it could not find or load he Qt platform plugin "windows". Reinstallning the application may fix this problem. Any ideas what I'm missing here? 回答1: I'd scratched my head over this some time ago. It turned out that this was caused not by missing qwindows.dll ,

C++ - How to chunk a file for simultaneous/async processing?

∥☆過路亽.° 提交于 2021-02-19 04:41:19
问题 How does one read and split/chunk a file by the number of lines? I would like to partition a file into separate buffers, while ensuring that a line is not split up between two or more buffers. I plan on passing these buffers into their own pthreads so they can perform some type of simultaneous/asynchronous processing. I've read the answer below reading and writing in chunks on linux using c but I don't think it exactly answers the question about making sure that a line is not split up into