[Solved] Can't use Vector or Deque

Hey all,

When trying to import vector or deque and without using them I’m getting the following:

In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/vector:60:0,
from xmas.cpp:11:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
In file included from ../inc/application.h:29:0,
from xmas.cpp:8:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected unqualified-id before 'const'
min(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected initializer before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected unqualified-id before 'const'
max(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected initializer before 'const'
In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/vector:60:0,
from xmas.cpp:11:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: 'std::min' declared as an 'inline' variable
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: template declaration of 'const _Tp& std::min'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected primary-expression before 'if'
if (__comp(__b, __a))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:244:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: 'max' declared as an 'inline' variable
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: template declaration of 'const _Tp& max'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected primary-expression before 'if'
if (__comp(__a, __b))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:265:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:266:5: error: expected declaration before '}' token
}
^

I checked some previous code that was working and i’m getting the same issue.

Has anyone come across this?

Thanks,

Kieran

Would you mind posting the code that results in these errors? From the looks of the error output both the “min” and “max” functions are being called incorrectly (as well as other issues I’m sure)

Sure, its just the neopixel example with vector added.
I can’t find any mention of min or max being overwritten in the neopixel lib.

/*
 * This is a minimal example, see extra-examples.cpp for a version
 * with more explantory documentation, example routines, how to 
 * hook up your pixels and all of the pixel types that are supported.
 *
 */

#include "application.h"
//#include "spark_disable_wlan.h" // For faster local debugging only
#include "neopixel/neopixel.h"
#include <vector>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 10
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() 
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
void loop() 
{
  rainbow(20);
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Heyya, is that a library or something?

If you are using the Web IDE, you need to copy the code and paste in a new file.

To use it, it should be something like #include vector.h instead.

If you can provide a link of what you are trying to use we can give you more advice :slight_smile:

Yep its the sample code from a library.

Looks like I’ve sorted it!
Turns out it was application.h overriding the min and max functions in the stl_algo lib.
Including vector before application.h seems to fix it anyway.

Thanks all for the help!

1 Like

The problem is the #defines in the Spark sources. (We will be removing these in due course!)

In the meaintime, you can add

#undef min
#undef max

before including the STL classes. e.g.

#include "application.h"
#include "neopixel/neopixel.h"
#undef min
#undef max
#include <vector>

That will remove the #defines and allow std::min etc. to be used.

Awesome, thank you!

1 Like