About using C++ STL

Hi there.

I want to do below.

  • Communicate two arduino 101s by SoftwareSerial to tell both data each other every some timing(e.g. 100 ms).
  • Received data is parsed and stored.
  • When complete own data and the other's data, print those data set by Serial1.

I think it should use FIFO system for stored and output.
Like a STL's queue.

Then, I want to use STL's queue and tried to use STL on arduino(genuino tho) 101.
Including and is succeeded.
vector's some functions looks like correctly operated.
( push_back, pop_back, erase, begin ,back etc... but at() can't compile.)
queue's almost methods can't compile.

Well, my questions are below.

  1. Is arduino 101 supported C++ STL or is there plans for supporting STL?
  2. Where can I get these infomations ?

Regards,
Daisuke

Hi Daisuke,
Arduino cores historically are not written to be STL compliant because they needed to redefine/reimplement some functions (AVR C++ standard library was too heavy for older boards).
New boards provide a full C++ experience but sometimes there are corner cases. It you could upload a test sketch showing the error we can try to debug it!

Thanks

Thanks for your reply.

New boards provide a full C++ experience but sometimes there are corner cases.

I think it's a awesome attempt !

I show the source code trying to use queue library.


#include
#include <CurieTimerOne.h>

std::queue hoge;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
CurieTimerOne.start(1000000, &timerInt);

}

void loop() {
// put your main code here, to run repeatedly:

if (hoge.size() != 0)
{
Serial.println(hoge.front());
hoge.pop();
}

}

void timerInt()
{
hoge.push(0);
}


Compile error occured when using queue.push() (as hoge.push(0) in source code.).
It said "undefined reference to `std::__throw_bad_alloc()'".
pop() and front() seem to passed compiler.

Regards,
Daisuke.

Great! The hacky but fast method is explained here

You can simply add an implementation of __throw_bad_alloc to your sketch

namespace std {
  void __throw_bad_alloc()
  {
    Serial.println("Unable to allocate memory");
  }

  void __throw_length_error( char const*e )
  {
    Serial.print("Length Error :");
    Serial.println(e);
  }
}

I believe we'll take care of supporting full STL implementation if there is enough request in the future :wink:

I appreciate for your code.
My code is running now.
Thank you so much.
Best wishes for your future success.

Best regards,
Daisuke

facchinm:
Great! The hacky but fast method is explained here

I believe we'll take care of supporting full STL implementation if there is enough request in the future :wink:

Hello facchinm,

Consider this to be a request, it is now the future.

I am using the SAMD21-based Arduinos which do have sufficient memory and processing speed for the STL. I find hand-coded linked lists to work for me but they are cumbersome and not at a higher level of abstraction. I found the ArduinoSTL library in the library manager to work fine, however it is based on a 2011 STL and the 2014 revision added some small but excellent improvements. I notice that the Gnu C++ compiler used by Arduino comes with the 2014 STL and though some examples work fine some others fail to compile under the Arduino IDE.

The future hardware offerings such as the Adafruit SAMD51 are the next step up in physical computing and their power just screams out for features such as the STL and beyond.

I would be willing to share in testing, examples, and documentation tasks to make this a standard set of features, and I would be glad to participate in implementation if my assistance could help.