Embedded Template Library

The Standard Template Library (STL) is used in a large number of C++ applications, but doesn't always get much of a look-in for many embedded projects, largely due to its use of the heap for many of its container classes.

I've added a library that, amongst other things, defines containers with statically allocated storage.
The library makes no use of the heap and does not utilise RTTI. All storage is defined at compile time. (It's also very cache friendly due to the storage for all containers being contiguous).

It does make use of some of the non-container aspects of the STL and therefore requires that a version of the STL is available to the Arduino project. A suitable implementation may be found here.

Apart from containers, the library provides many other templated features. To find out more visit www.etlcpp.com
(Be aware that the documentation is a little behind at the moment and doesn't mention some of the lastest hashing containers).

The library is intended to be generally useful across many platforms, and has been extensively unit tested (current count is 1154 tests) with Microsoft and GCC compilers. That said the amount of testing on the Arduino platform has so far been limited to a couple of simple examples on my Genuino Zero, so be prepared for possible compilation issues. If you find anything odd then raise it on the github page.

An example 'BlinkList' is supplied to get you started. This builds on the 'Blink' demo by creating two lists of delay times, and cycling through them consecutively.

To install it, search for 'Embedded Template Library' in the library manager.

Have fun!

jwellbelove:
To install it, search for 'Embedded Template Library' in the library manager.

Well it hasn't been added to Library Manager yet but soon come and until then easy enough to manually install from your GitHub repository.

Sounds interesting, thanks for sharing! Per

The library has been developed slowly over several years, starting off as a personal library of 'good ideas' that I had been experimenting with. Eventually I decided to pull the code together as a library after I realised that there were no real open source (or even closed) alternatives that met my requirements. I think it would be a very useful resource for embedded programmers and I've had encouraging responses from other coders in the industry. The big problem is it is in a catch-22 situation where people are cautious about using a library in commercial products that isn't already widely used, and it isn't widely used because people are cautious!

As users of Arduino boards are likely to be up for a little bit more experimentation I thought that they would be more inclined to give it a try and hopefully give it a bit more exposure (and the extra beta testing would also be a plus).

I'm currently working on a string implementation and I have outline plans for a set of cache containers and a timer service class that will hook into a hardware timer, allowing for one-shot, and repeating timer callbacks.

In the long term I have tentative plans for a messaging system and a cooperative scheduler.

Version 8.1.0. available.

Added etl::debounce class to debounce signals and keys.

  • Simple debounce
  • Debounce and hold detection
  • Debounce, hold and repeat detection.

See etl::debounce

Added splice_after and merge to intrusive lists.

Bug fix for intrusive_forward_list::resize() when resizing down.

Bug fix for 16bit parity calculation.

Fixed incompatibilities and warnings with GCC.

Optimised hash calculations for etl::bloom_filter.

Added platform.h for internal library use to eradicate to need for project wide macro definitions.

Remove unused code.

Updated unit tests.

I installed the ETL library 8.1.0 by Library Manager.
created a new project "mytest_etl", and included the libray.
but can not pass the compiling.
Could you give me some advice? Thanks.
error as follows:

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from C:\Users\jy\Documents\Arduino\mytest_etl\mytest_etl.ino:1:0:

C:\Users\jy\Documents\Arduino\libraries\Embedded_Template_Library\src/algorithm.h:38:21: fatal error: algorithm: No such file or directory

#include

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

The ETL library has a dependency on some of the algorithms from the standard template library (STL) which the Arduino compiler is not suppplied.

A port of the STL for AVR processors can be found here...

Hopefully I shall be able to add string classes in the next few days, plus a couple of bug fixes and performance improvements.

Thanks for downloading.

I'm getting the following error when trying to include "deque.h"

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\iosfwd:21:0,

from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\iterator:35,

from C:\Users\Brad\Documents\Arduino\libraries\Embedded_Template_Library\src/deque.h:36,

from C:\Users\Brad\Documents\Arduino\snake\snake.ino:1:

C:\Users\Brad\Documents\Arduino\libraries\Embedded_Template_Library\src/char_traits.h:35:24: fatal error: algorithms.h: No such file or directory

#include "algorithms.h"

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

I have the port for STL from Andy Brown's site installed as well. Does this have anything to do with algorithm.h being in your library and you including algorithms.h?

There's a mistake in char_traits.h. The line should read #include "algorithm.h".

Its correct in my current development branch which I shall be merging with the master soon (including new string containers!)

In the mean time, just remove the offending 's'.

John.

New library updates. 8.2.0

Added string containers.
etl::string
etl::wstring
etl::u16string
etl::u32string

Added pointer specialisation for etl::vector thereby reducing code size when using multiple instances of vectors of differing pointer types.

Modified the library for greater cross compiler compatibility.

Added a method of definition of typesafe typedefs

The problem

typedef int event_id_t;
typedef int command_id_t;

event_id_t   event;
command_id_t command;

event = command; [b][color=red]// OOPS!, Run time error. :-([/color][/b]

The solution

ETL_TYPEDEF(int, event_id_t);
ETL_TYPEDEF(int, command_id_t);

event_id_t   event;
command_id_t command;

event = command; [b][color=green]// Compile time error. :-)[/color][/b]

Has anyone been able to use Embedded Template Library on Arduino successfully?
I am trying to use it, but there so many issues. So, I wonder what kind of experience the others had with it.

What issues are you having?
Have you installed the STL for AVR processors? The ETL relies on a few algorithms from the STL.

I may not be able to respond for the next couple of days, but I can help as soon as I get back.

Arduino:1.8.1 (Windows 10),Board: "Arduino/Genuino Uno"
error as follows:
In file included from C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\src/pool.h:37:0,

from C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\src/private/list_base.h:39,

from C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\src/ilist.h:42,

from C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\src/list.h:36,

from C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\examples\BlinkList\BlinkList.ino:8:

C:\Users\zhuang\Documents\Arduino\libraries\Embedded_Template_Library\src/integral_limits.h:34:19: fatal error: climits: No such file or directory

#include

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.
I have the port for STL from Andy Brown's site installed as well.
Could you give me some advice? Thanks.

It seems like the compiler doesn't understand the C++ version of the limits.h header.
Looks like I'll have to change it to the C version <limits.h>

Done and pushed to master branch.

Could someone explain how to install this library in the Arduino IDE and compile a rudimentary test program for a basic AVR based board.

TIA.

Hi Jim,

I'll dig out my Zero board and take a look. It's a long time since I tried the ETL on that platform.

Also take a look at setup