boost-preprocessor

BOOST_PP_REPEAT with array

我的未来我决定 提交于 2019-12-22 08:49:47
问题 I have struct like : struct E1 { typedef boost::tuple< boost::optional< N::type_A >, // N - namespace boost::optional< N::type_B >, ................... boost::optional< N::type_X > //arbitrary number of, maximal is 7 > data_type; // for access by name boost::optional<N::type_A> const& type_A() const { return boost::get<0>(data); } boost::optional<N::type_B> const& type_B() const { return boost::get<1>(data); } ..................................... boost::optional<N::type_X> const& type_X()

Can I append to a preprocessor macro?

↘锁芯ラ 提交于 2019-12-18 16:07:32
问题 Is there any way in standard C—or with GNU extensions—to append stuff to a macro definition? E.g. , given a macro defined as #define List foo bar can I append bas so that it List expands as if I’d defined it #define List foo bar bas ? I was hoping I could do something like this: #define List foo bar bas #define List_ Expand(List) #undef List #define List Expand(List_) quux but I can’t figure out how to define the Expand() macro so it’ll do what I want. Motivation: I’m playing with

How do I print out a comma multiple times using Boost Preprocessor

依然范特西╮ 提交于 2019-12-12 23:05:09
问题 I need to use a variadic macro to expand to multiple variations of a class. Since they need to have different names based on the macro input I can't simply use templates. The problem is that I can't expand the comma ( , ) symbol, and my class has functions which take multiple parameters (for which I need to use the comma symbol). boost provides the BOOST_PP_COMMA() macro which expands to a comma, but it only works outside of loop constructs. I'm guessing the issue is that BOOST_PP_COMMA() is

How to zip multiple Boost Preprocessor sequences?

我是研究僧i 提交于 2019-12-08 04:07:08
问题 Given multiple Boost Preprocessor sequences: #define S1 (a)(b)(c) #define S2 (1)(2)(3) #define S3 (x1)(x2)(x3) How do I zip them using the preprocessor so the end result would be ((a)(1)(x1))((b)(2)(x2))((c)(3)(x3)) ? Notes I came up with my own answer, but I'm open to accepting better solutions than provided by my answer below in reasonable time. Please refrain from removing the c tag since this Boost.Preprocessor works well with C++ as well as C, and my question targets both languages. 回答1:

How to get function signature via preprocessor define written before it?

南笙酒味 提交于 2019-12-08 01:38:59
问题 I want to create a define to parse function signature and using Boost Preprocessor create something like this: MY_DEFINE std::string fun(int t, float b) { or at least: MY_DEFINE(std::string)(fun)(int t, float b) { that would generate: class fun_in { int t; float b; } class fun_out { std::string value; } void my_fun_wrapper(int t, float b) { } std::string fun(int t, float b) { my_fun_wrapper(t, b); for each function with that define. Is it possible to create such define wrapper for function of

C++ method declaration including a macro

只愿长相守 提交于 2019-12-07 16:55:26
I'm using QuickFAST library and while checking it I found this class declaration which I don't seem to really get ! I mean what does a macro name before the class name ! class QuickFAST_Export Message : public FieldSet also I found this declaration friend void QuickFAST_Export intrusive_ptr_add_ref(const Field * ptr); and again I don't get the use of this declaration ! for more info here's the QuickFAST_Export.hpp #ifdef _MSC_VER # pragma once #endif #ifndef QUICKFAST_EXPORT_H #define QUICKFAST_EXPORT_H // Compile time controls for library generation. Define with /D or #define // To produce or

Implementing enumerate_foreach based on Boost foreach

谁说我不能喝 提交于 2019-12-07 14:18:27
问题 To preface this question: I've been implementing various C++ utility functions and (when I have to) macros in a larger toolkit for my own use. Recently I had been making a variety of loop macros based on BOOST_FOREACH as well as iterable conscious functions. Long story short, I ran into difficulty making an enumerate-loop which uses BOOST_FOREACH but with an additional parameter passed which is incremented on every iteration of the loop. This would function much like the enumerate command in

Avoid if-else branching in string to type dispatching

孤者浪人 提交于 2019-12-06 16:15:39
问题 Usually when you write a CLI tool which accepts parameter you have to deal with them. Most of the time you want to switch between behaviours based on the value of an argument. The following is a common use case, where the program accepts a type and then prints something based on that type. I am using Boost to pre-process and auto generate the whole if-else branches. This is very nice in terms of maintainability as I only need to update a define when I introduce a new type. On the other hand

How to create proxy class?

♀尐吖头ヾ 提交于 2019-12-06 14:18:08
问题 Having N difrent classes that have no public data fields, only methods (that do not overlap), how to create unifiing them all proxy class via boost preprocessor? For example we had classes: A that had method do(); and class B had method data(); . I wonder if there is a way (using Boost Preprocessor for example) to create a proxy class that would have all methods from A and B (here do() data() ) and a constructor taking in that pointers to that classes instances - one for A and one for B? So

How to get function signature via preprocessor define written before it?

元气小坏坏 提交于 2019-12-06 11:46:10
I want to create a define to parse function signature and using Boost Preprocessor create something like this: MY_DEFINE std::string fun(int t, float b) { or at least: MY_DEFINE(std::string)(fun)(int t, float b) { that would generate: class fun_in { int t; float b; } class fun_out { std::string value; } void my_fun_wrapper(int t, float b) { } std::string fun(int t, float b) { my_fun_wrapper(t, b); for each function with that define. Is it possible to create such define wrapper for function of N incoming arguments and any return type via Boost Preprocessor? Paul Fultz II Well, the preprocessor