static-if

static if in plain c++?

会有一股神秘感。 提交于 2020-01-12 07:03:54
问题 Problem in short: How could one implement static if functionality, proposed in c++11, in plain c++ ? History and original problem: Recently I came up with a problem like this. I need a class Sender with an interface like class Sender { void sendMessage( ... ); void sendRequest( ... ); void sendFile( ... ); // lots of different send methods, not important actually } In some cases I will need to create a DoubleSender , i.e. an instance of this class, which would call its methods twice, i.e.

static_if in C99's preprocessor

和自甴很熟 提交于 2019-12-18 05:16:28
问题 Is it possible to implement static_if in C99? #define STATIC_IF(COND, ...) \ if (COND) MACRO1(__VA_ARGS__); \ else MACRO2(__VA_ARGS__); How can I properly implement STATIC_IF(…) in here? Depending on COND the arguments either should be passed to MACRO1 or MACRO2 , but the arguments for both macros look differently. COND is statically testable, something like sizeof (…) > 42 . #if COND then #define STATIC_IF MACRO1 … wouldn't work for my use case. I cannot use compiler specific solutions. 回答1: