pkourany / Adafruit_mfGFX_IDE

Multifont GFX library for IDE, adapted from Adafruit_GFX library
Other
11 stars 21 forks source link

Please replace #define swap() #1

Closed ScruffR closed 4 years ago

ScruffR commented 8 years ago

That macro makes the use of several std:: classes rather difficult.

This rather simple test throws a load of errors all in std::vector

#include "Adafruit_mfGFX/Adafruit_mfGFX.h"
#include <vector>
void setup() { }
void loop() { }

Sure #undef swap does fix that, but still ;-)

pkourany commented 8 years ago

@ScruffR, the question is why does the swap macro cause issues? It would be very simple to wrap the definition like this:

#ifndef swap
#define swap(a, b) { int16_t t = a; a = b; b = t; }
#endif

Could you this that a shot?

ScruffR commented 8 years ago

The problem seems to be that once swap is defined as macro, the swap function in std::vector and other std:: containers is hidden by the macro.

On the other hand, if I flip the includes round, any call to vector::swap results in an error. So the only way around this is to rename the swap macro or limit its lifetime to the GFX library only.

BTW, the same issue is presend with the Adafruit_GFX lib.

pkourany commented 8 years ago

Then perhaps the best solution is to change swap to swapBytes or something similar.

ScruffR commented 8 years ago

Yup, that'd help

pkourany commented 8 years ago

Do you want to do a PR? Otherwise, I'll get to it this weekend.

ScruffR commented 8 years ago

I'll see how my home schedule looks like this weekend ;-)