I was trying out various implementations of the C++ STL libraries with Arduino 1.6.6 and figured it might be useful to post my notes here. Anyone have any experience or thoughts on these?
(See also Gammon Forum : Programming : STL : STL for microprocessors)
STLPort AVR
This is a modification of stlport to AVR.
Diff: Comparing 408d252b2032fb80ae58a9325cbe2363d1e3f60c...STLport-master-avr · vancegroup/stlport-avr · GitHub
Almost up-to-date w/ STLPort 5.2 (see: STLport download | SourceForge.net)
(Apparently, STLPort is an updated version of the SGI STL used by Andy Brown's AVR STL below, so this may be more robust / modern than that one.)
StandardCplusplus
Port of uClibc++ (http://cxx.uclibc.org) to Arduino. Seems to work with Arduino 1.6.6.
Also see: GitHub - rpavlik/StandardCplusplus: Standard C++ for Arduino (port of uClibc++)
Andy Brown’s AVR STL
SGI STL + uSTL’s streams. Works in Arduino 1.6.6 w/ minor patches:
diff --git a/pnew.cpp b/pnew.cpp
index 5d1c6a0..b96b62c 100755
--- a/pnew.cpp
+++ b/pnew.cpp
@@ -9,6 +9,8 @@
* Global placement operator new
*/
+#include <cstddef>
+
void* operator new(size_t size_,void *ptr_)
{
return ptr_;
diff --git a/stl_vector.h b/stl_vector.h
index 18e1bc4..19dde40 100755
--- a/stl_vector.h
+++ b/stl_vector.h
@@ -114,7 +114,7 @@ struct _Vector_base
_Base::_M_end_of_storage = _Base::_M_start + __n;
}
- ~_Vector_base() { _M_deallocate(_Base::_M_start, _Base::_M_end_of_storage - _Base::_M_start); }
+ ~_Vector_base() { this->_M_deallocate(_Base::_M_start, _Base::_M_end_of_storage - _Base::_M_start); }
};
#else /* __STL_USE_STD_ALLOCATORS */
avrstl
https://code.google.com/p/avrstl/
A port of an old version of uSTL to avr. Doesn’t compile on Arduino 1.6.6. With this code:
#undef max
#undef min
typedef long ssize_t;
typedef long off_t;
#include <ustl.h>
void setup() {}
void loop() {}
I get:
In file included from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/uutility.h:14:0,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ualgobase.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/cmemlink.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/memlink.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/memblock.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/uvector.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/uspecial.h:9,
from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ustl.h:9,
from /Users/mellis/Documents/Arduino/avrstl-test/avrstl-test.ino:7:
/Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ulimits.h:91:15: error: expected unqualified-id before 'alignof'
inline size_t alignof (const T&)
^
/Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ulimits.h:100:31: error: expected unqualified-id before 'alignof'
template <> inline size_t alignof (const type&) { return (grain); } }
^
/Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ustring.h:266:1: note: in expansion of macro 'ALIGNOF'
ALIGNOF (ustl::string, alignof (string::value_type()))
^
In file included from /Users/mellis/Documents/Arduino/libraries/avrstl-read-only/ustl.h:9:0,
from /Users/mellis/Documents/Arduino/avrstl-test/avrstl-test.ino:7:
/Users/mellis/Documents/Arduino/libraries/avrstl-read-only/uspecial.h:114:15: error: expected unqualified-id before 'alignof'
inline size_t alignof (const vector<T>&)
^
/Users/mellis/Documents/Arduino/libraries/avrstl-read-only/uspecial.h:155:15: error: expected unqualified-id before 'alignof'
inline size_t alignof (const tuple<N,T>&) { return (alignof (NullValue<T>())); }
^
avrstl-test:9: error: 'namespaceustl' does not name a type
void setup() {}
^
exit status 1
'namespaceustl' does not name a type
Not sure what’s going on.
uSTL
Seems to be well-maintained but doesn’t run on AVR. At least, not easily.
libavrstdc++
https://libavrstdcpp.codeplex.com
Looks incomplete / unfinished.