boost-preprocessor

Macro-based counter

倖福魔咒の 提交于 2021-02-19 07:43:26
问题 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

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_PP expand sequence in the empty sequence case

我怕爱的太早我们不能终老 提交于 2021-02-08 02:58:30
问题 Using BOOST_PP I can expand a macro into multiple comma separated values with an additional token, as can be seen in the below code. However, it doesn't work in the no-argument case. #define BOOST_PP_VARIADICS #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ADD_TOKEN(r, token, i, e) \ BOOST_PP_COMMA_IF(i) token(e) #define WRAP(...) \ BOOST_PP_SEQ_FOR_EACH_I(ADD_TOKEN, decltype,

BOOST_PP expand sequence in the empty sequence case

蹲街弑〆低调 提交于 2021-02-08 02:57:29
问题 Using BOOST_PP I can expand a macro into multiple comma separated values with an additional token, as can be seen in the below code. However, it doesn't work in the no-argument case. #define BOOST_PP_VARIADICS #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ADD_TOKEN(r, token, i, e) \ BOOST_PP_COMMA_IF(i) token(e) #define WRAP(...) \ BOOST_PP_SEQ_FOR_EACH_I(ADD_TOKEN, decltype,

Compile time switch generation based on number of fields in structure

◇◆丶佛笑我妖孽 提交于 2020-01-17 11:17:11
问题 How in C++03 get in compile time number of members of chosen struct? I was experimenting with BOOST_FUSION_ADAPT_STRUCT but I did't get any working example. I want to generate switch statement in compile time, where there will be one case per each member. So lets say we have struct with 3 members then I want to generate this switch: switch(val) { case 0: break; case 1: break; case 2: break; } In each statement I will call template function with some parameters. One of this parameters is a

why this PP_ARG_COUNT macro need a PP_EXPAND?

我只是一个虾纸丫 提交于 2020-01-14 06:10:14
问题 #include <type_traits> #include <iostream> using namespace std; // Expand #define PP_EXPAND(X) X // Counter Arguments count #define PP_ARG_COUNT(...) PP_EXPAND( PP_ARG_POPER(__VA_ARGS__, 5, 4, 3, 2, 1, 0) ) #define PP_ARG_COUNT2(...) PP_ARG_POPER(__VA_ARGS__, 5, 4, 3, 2, 1, 0) #define PP_ARG_POPER(_1, _2, _3, _4, _5, N, ...) N int main() { cout << PP_ARG_COUNT(1, 2, int) << endl; cout << PP_ARG_COUNT2(1, 2, int) << endl; cout << PP_ARG_POPER(1, 2, int, 5, 4, 3, 2, 1 0) << endl; return 0; } i

How do I show the value of a #define at compile-time?

主宰稳场 提交于 2020-01-09 08:25:25
问题 I am trying to figure out what version of Boost my code thinks it's using. I want to do something like this: #error BOOST_VERSION but the preprocessor does not expand BOOST_VERSION. I know I could print it out at run-time from the program, and I know I could look at the output of the preprocessor to find the answer. I feel like having a way of doing this during compilation could be useful. 回答1: I know that this is a long time after the original query, but this may still be useful. This can be

How to use boost::preprocessor to unzip a sequence?

匆匆过客 提交于 2020-01-02 04:24:44
问题 How to use boost::preprocessor to unzip a sequence of pairs? For example, I have a sequence as below (comma between doesn't matter) (int,x)(double,y)(float,z) or (int,x),(double,y),(float,z) or ((int)(x))((double)(y))((float)(z)) and want to convert to int,double,float and x,y,z By using macor like UNZIP(i, seq) where i is the index. 回答1: Unzipping of (int, x, 10)(double, y, 20)(float, z, 30) , i.e. sequence without commas between elements. LIVE DEMO #include <boost/preprocessor/punctuation

Recursive explicit template instantiation to export symbols for a library

ぐ巨炮叔叔 提交于 2019-12-23 07:55:26
问题 In my previous question I asked is recursive explicit template instantiation possible. I saw that it is indeed possible; however, this instantiation turns out to be effective locally only, the symbols of the recursively instantiated template are not exported to the object file and thus do not appear in the (shared) library. So I ask question here more precisely as in my previous post: Given a template like template<int dim> class Point { ... }; this template can be instantiated explicitly

C++ method declaration including a macro

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 04:37:11
问题 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