Boost logo

Boost Users :

From: Johan 't Hart (jopie64_at_[hidden])
Date: 2007-06-18 18:40:57


Thanks alot! This is very useful!

Johan

"Tobias Schwinger" <tschwinger_at_[hidden]> schreef in bericht
news:f540bg$ksu$1_at_sea.gmane.org...
> Johan 't Hart wrote:
>> Hi,
>>
>> I don't know if boost has a solution for my problem, or there is just
>> something simple I miss...
>> I've been struggling with some preprocessor things. I'm trying to use it
>> for
>> versioning. Here is the problem:
>>
>> I've got these defines:
>>
>> #define VERSION_MAJOR 5
>> #define VERSION_MINOR 4
>> #define VERSION_BUILD 3
>> #define VERSION_SUBBUILD 2
>>
>> Sometimes I just need a string like: "5.4.3.2". I do it like this:
>>
>> #define STRINGER_(s) #s
>> #define STRINGER(s) STRINGER_(s)
>> #define VERSION_STRING_1 \
>> STRINGER(VERSION_MAJOR) "." \
>> STRINGER(VERSION_MINOR) "." \
>> STRINGER(VERSION_BUILD) "." \
>> STRINGER(VERSION_SUBBUILD)
>>
>> So VERSION_STRING_1 is "5.4.3.2"
>> Now I need a string like: "5.4.3b". (Note the 'b'. When VERSION_SUBBUILD
>> ==
>> 3, I want it to be a 'c' etc)
>> How do I do this in a preprocessor command???? The char is simple, its
>> (VERSION_SUBBUILD+'a'-1).
>
> You need a lookup table to do it all in the preprocessor, AFAIK:
>
> #include <boost/preprocessor/cat.hpp>
> #include <boost/preprocessor/stringize.hpp>
>
> #define VERSION_ID(major,minor,build,sub_build) \
> BOOST_PP_STRINGIZE( \
> major.minor.build.BOOST_PP_CAT(N2LCC_,sub_build) )
>
> #define N2LCC_1 a
> #define N2LCC_2 b
> #define N2LCC_3 c
> #define N2LCC_4 d
> #define N2LCC_5 e
> #define N2LCC_6 f
> #define N2LCC_7 g
> #define N2LCC_8 h
> #define N2LCC_9 i
> #define N2LCC_10 j
> #define N2LCC_11 k
> #define N2LCC_12 l
> #define N2LCC_13 m
> #define N2LCC_14 n
> #define N2LCC_15 o
> #define N2LCC_16 p
> #define N2LCC_17 q
> #define N2LCC_18 r
> #define N2LCC_19 s
> #define N2LCC_20 t
> #define N2LCC_21 u
> #define N2LCC_22 v
> #define N2LCC_23 w
> #define N2LCC_24 x
> #define N2LCC_25 y
> #define N2LCC_26 z
>
> VERSION_ID(2,1,3,1)
>
> Regards,
> Tobias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net