Coder Social home page Coder Social logo

etlcpp / etl Goto Github PK

View Code? Open in Web Editor NEW
2.0K 60.0 359.0 26.27 MB

Embedded Template Library

Home Page: https://www.etlcpp.com

License: MIT License

C++ 97.74% C 1.09% Batchfile 0.01% CMake 0.63% Python 0.09% Meson 0.07% Shell 0.38%
c-plus-plus embedded-applications cpp templates library algorithms containers

etl's Introduction

Embedded Template Library (ETL)

GitHub release (latest by date) Release date Standard License GitHub contributors

CI Build status

CI CI CI CI CI

CI CI CI CI CI

Codacy Badge

Project documentation

Motivation

C++ is a great language to use for embedded applications and templates are a powerful aspect. The standard library can offer a great deal of well tested functionality, but there are some parts of the standard library that do not fit well with deterministic behaviour and limited resource requirements. These limitations usually preclude the use of dynamically allocated memory and containers with open ended sizes.

What is needed is a template library where the user can declare the size, or maximum size of any object upfront. Most embedded compilers do not currently support the standard beyond C++ 03, therefore excluding the programmer from using the enhanced features of the later library.

This is what the ETL attempts to achieve.

Summary

The ETL is not designed to completely replace the STL, but complement it. Its design objective covers three areas.

  • Create a set of containers where the size or maximum size is determined at compile time. These containers are direct equivalents of those supplied in the STL.
  • Be compatible with C++ 03 but implement as many of the C++ 11/14/17/20 additions as possible.
  • Add other useful components that are not present in the standard library.

The embedded template library has been designed for lower resource embedded applications. It contains a set of containers, algorithms and utilities, some of which emulate parts of the STL. There is no dynamic memory allocation. The library makes no use of the heap. All of the containers have a fixed capacity allowing all memory allocation to be determined at compile time. The library is intended for any compiler that supports C++98/03/11/14/17/20.

Main features

  • Cross platform. This library is not specific to any processor type.
  • No dynamic memory allocation
  • No RTTI required
  • Very little use of virtual functions. They are used only when they are absolutely necessary for the required functionality
  • A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector, map, set, etc.)
  • As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly
  • Templated compile time constants
  • Templated design pattern base classes (Visitor, Observer)
  • Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.)
  • Type-safe enumerations
  • Type-safe typedefs
  • 8, 16, 32 & 64 bit CRC calculations
  • Checksums & hash functions
  • Variants (a type that can store many types in a type-safe interface)
  • Choice of asserts, exceptions, error handler or no checks on errors
  • Unit tested (currently over 6480 tests), using VS2019, GCC 8.1.0, , GCC 9.3.0, Clang 9.0.0 & 10.0.0
  • Many utilities for template support.
  • Easy to read and documented source.
  • Free email support

Any help porting the library to work under different platforms and compilers would be gratefully received. I am especially interested in people who are using Keil, IAR, Green Hills, TI Code Composer etc, bare metal or RTOS, and DSPs.

See (https://www.etlcpp.com) for up-to-date information.

Installing this library

You can find the setup steps here.

CMake

One way to use this library is to drop it somewhere in your project directory and then make the library available by using add_subdirectory

add_subdirectory(etl)
add_executable(foo main.cpp)
target_link_libraries(foo PRIVATE etl::etl)

If ETL library is used as a Git submodule it may require additional configuration for proper ETL version resolution by allowing the lookup for Git folder outside of the library root directory.

set(GIT_DIR_LOOKUP_POLICY ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
add_subdirectory(etl)

If you want to install this library with CMake, you can perform the following steps. On Linux, super user rights might be required to install the library, so it might be necessary to add sudo before the last command:

git clone https://github.com/ETLCPP/etl.git
cd etl
git checkout <targetVersion>
cmake -B build .
cmake --install build/

After the library has been installed, you can use find_package to use the library. Replace <majorVersionRequirement> with your desired major version:

find_package(etl <majorVersionRequirement>)
add_executable(foo main.cpp)
target_link_libraries(foo PRIVATE etl::etl)

Alternatively you can use FetchContent, replacing <targetVersion> with the version to install based on a git tag:

Include(FetchContent)

FetchContent_Declare(
  etl
  GIT_REPOSITORY https://github.com/ETLCPP/etl
  GIT_TAG        <targetVersion>
)

FetchContent_MakeAvailable(etl)

add_executable(foo main.cpp)
target_link_libraries(foo PRIVATE etl::etl)

Arduino library

The content of this repo is available as a library in the Arduino IDE (search for the "Embedded Template Library" in the IDE library manager). The Arduino library repository is available at https://github.com/ETLCPP/etl-arduino, see there for more details.

etl's People

Contributors

aboseley avatar annius avatar apmorton avatar areksredzki avatar ashleyroll avatar benedekkupper avatar bku-sue avatar bolry avatar chiraffollo avatar dhebbeker avatar drewr95 avatar fermentedfly avatar finger42 avatar gatorque avatar ivankravets avatar jesseli2002 avatar jovere avatar jputcu avatar jwellbelove avatar mampfes avatar mchodzikiewicz avatar mhx avatar mipsters avatar phillipjohnston avatar robamu avatar rolan-reznik avatar scott-eddy avatar skorokhod avatar twam avatar un-done avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

etl's Issues

Problems migrating from STL to ETL

I really appreciate your realisation of an STL version for embedded applications. I once worked on a project where we needed to rewrite a lot of the code, because a certain STL function was not available on the target platform...

I am the maintainer of JSON for Modern C++ (https://github.com/nlohmann/json), a header-only library to make JSON a first-class datatype in C++11. I am using a lot of the STL, but at its core, the library is just a wrapper around std::map, std::vector, and std::string. As these containers are used as template types, it should be possible to replace them with the ETL versions. (see nlohmann/json#361)

What do you think?

I tried to compile a small program myself, but the moment I, for instance, include "vector.h", I get a lot of compiler errors even though I do not use the vector. Is there any migration guide available or a list of gotchas?

Program:

#include <vector.h>

int main()
{
	return 0;
}

Output:

g++-5 -Ietl    testetl.cpp   -o testetl
In file included from etl/alignment.h:37:0,
                 from etl/vector.h:40,
                 from testetl.cpp:1:
etl/array.h: In function 'T& etl::get(etl::array<T, MAXN>&)':
etl/static_assert.h:37:77: error: there are no arguments to 'static_assert' that depend on a template parameter, so a declaration of 'static_assert' must be available [-fpermissive]
   #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message)
                                                                             ^
etl/array.h:457:5: note: in expansion of macro 'STATIC_ASSERT'
     STATIC_ASSERT(I < MAXN, "Index out of bounds");
     ^
etl/static_assert.h:37:77: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
   #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message)
                                                                             ^
etl/array.h:457:5: note: in expansion of macro 'STATIC_ASSERT'
     STATIC_ASSERT(I < MAXN, "Index out of bounds");
     ^
etl/array.h: In function 'const T& etl::get(const etl::array<T, MAXN>&)':
etl/static_assert.h:37:77: error: there are no arguments to 'static_assert' that depend on a template parameter, so a declaration of 'static_assert' must be available [-fpermissive]
   #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message)
                                                                             ^
etl/array.h:472:5: note: in expansion of macro 'STATIC_ASSERT'
     STATIC_ASSERT(I < MAXN, "Index out of bounds");
     ^
make: *** [testetl] Error 1

Suggestion to modify location of header files

Issue to track work on a modified directory structure to e.g. reduce name collisions for header files. Previously discussed in #64, but better off as a separate issue.

Background: ETL currently has .h and .cpp files in etl/src/. If your project e.g. include other 3rd party libraries, containing e.g. queue.h, there's a risk of name collision with e.g. etl/src/queue.h.

Possible solution: Move ETL headers to: etl/include/etl/ and let the project add etl/include/ to it's include paths. The source code would then include "queue.h" by doing: #include "etl/queue.h"

Use of "const" with parameter type derived from etl::paramter_type<T>

Hi

The compiler I'm using says:
"etl/src/imap.h", line XXX: type qualifier are meaningless here"
mapped_type& operator [](const key_value_parameter_t key)
^
(about the "const")

(not the latest version of ETL here, but I'm still updating)

when I'm using

etl::map<std::string, int, 10> tmap;
tmap["0"] = 1;
std::cout << tmap["0"] << std::endl;

EDIT:
No problem if I use int instead of std::string

Maybe the const is indeed not needed (thanks to the handy template etl::paramter_type) . I'm aware that it is done this way in many places...
Before I change anything in my use of your code, and since my knowledge of ETLCPP is limited, I'd like to have your opinion.
Regards

Damien

Non replies to issues!

Apologies to anyone who raised an issue recently and didn't get a reply. I changed my default reply address in my email client which meant that any replies I sent back to Github disappeared into a black hole!

vector of reference to class fails to compile

Hi,

When trying to create and initialise a vector to a reference of a class, the compilation fails.

class AClass 
{
};

AClass a;
AClass b;

etl::vector<AClass&, 5> v = {a, b};		

when compiled in VS2015, I get the following error:

1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(66): error C2528: 'pointer': pointer to reference is illegal
1>  c:\ash\git\r4\externalrepos\etl\src\vector.h(59): note: see reference to class template instantiation 'etl::ivector<T>' being compiled
1>          with
1>          [
1>              T=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass &
1>          ]
1>  c:\ash\git\r4\firmware\pic32\lib\_unittests\configtests\configloadtests.cpp(112): note: see reference to class template instantiation 'etl::vector<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass &,5>' being compiled
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(67): error C2528: 'const_pointer': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(68): error C2528: 'iterator': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(69): error C2528: 'const_iterator': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(70): error C2528: '<template-parameter>': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(71): error C2528: '<template-parameter>': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): error C2528: '<template-parameter>': pointer to reference is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(619): error C2528: '<template-parameter>': pointer to reference is illegal
1>  c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): note: see reference to class template instantiation 'std::iterator_traits<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass &(*)>' being compiled
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): error C2039: 'difference_type': is not a member of 'std::iterator_traits<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass &(*)>'
1>  c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): note: see declaration of 'std::iterator_traits<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass &(*)>'
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): error C3646: 'difference_type': unknown override specifier
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(73): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(759): error C2528: 'p_buffer': pointer to reference is illegal
1>c:\ash\git\r4\externalrepos\etl\src\ivector.h(785): error C2528: 'p_buffer': pointer to reference is illegal

in XC32 (PIC32 compiler based in GCC) I get:

Config/../../../../ExternalRepos/etl/src/ivector.h: In instantiation of 'class etl::ivector<Config::foo()::AClass&>':
In file included from Config/../../../../ExternalRepos/etl/src/vector.h:38:0,
                 from Config/ConfigurationManager.cpp:6:
Config/../../../../ExternalRepos/etl/src/vector.h:58:9:   required from 'class etl::vector<Config::foo()::AClass&, 5ul>'
Config/ConfigurationManager.cpp:52:27:   required from here
Config/../../../../ExternalRepos/etl/src/ivector.h:66:16: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef T*                                    pointer;
                ^
Config/../../../../ExternalRepos/etl/src/ivector.h:67:22: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef const T*                              const_pointer;
                      ^
Config/../../../../ExternalRepos/etl/src/ivector.h:68:16: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef T*                                    iterator;
                ^
Config/../../../../ExternalRepos/etl/src/ivector.h:69:22: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef const T*                              const_iterator;
                      ^
Config/../../../../ExternalRepos/etl/src/ivector.h:70:45: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef std::reverse_iterator<iterator>       reverse_iterator;
                                             ^
Config/../../../../ExternalRepos/etl/src/ivector.h:71:51: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
                                                   ^
Config/../../../../ExternalRepos/etl/src/ivector.h:73:70: error: forming pointer to reference type 'Config::foo()::AClass&'
     typedef typename std::iterator_traits<iterator>::difference_type difference_type;
                                                                      ^
In file included from Config/../../../../ExternalRepos/etl/src/vector.h:38:0,
                 from Config/ConfigurationManager.cpp:6:
Config/../../../../ExternalRepos/etl/src/ivector.h:759:5: error: forming pointer to reference type 'Config::foo()::AClass&'
     ivector(T* p_buffer, size_t MAX_SIZE)
     ^
Config/../../../../ExternalRepos/etl/src/ivector.h:785:8: error: forming pointer to reference type 'Config::foo()::AClass&'
     T* p_buffer;
        ^
Config/../../../../ExternalRepos/etl/src/vector.h: In instantiation of 'etl::vector<T, MAX_SIZE_>::vector(TIterator, TIterator) [with TIterator = Config::foo()::AClass; T = Config::foo()::AClass&; long unsigned int MAX_SIZE_ = 5ul]':
In file included from Config/ConfigurationManager.cpp:6:0:
Config/ConfigurationManager.cpp:52:36:   required from here
Config/../../../../ExternalRepos/etl/src/vector.h:104:59: error: forming pointer to reference type 'Config::foo()::AClass&'
       : ivector<T>(reinterpret_cast<T*>(&buffer), MAX_SIZE)
                                                           ^
Config/../../../../ExternalRepos/etl/src/ivector.h: In instantiation of 'void etl::ivector<T>::destroy_element() [with T = Config::foo()::AClass&]':
In file included from Config/../../../../ExternalRepos/etl/src/vector.h:38:0,
                 from Config/ConfigurationManager.cpp:6:
Config/../../../../ExternalRepos/etl/src/ivector.h:780:27:   required from 'void etl::ivector<T>::initialise() [with T = Config::foo()::AClass&]'
Config/../../../../ExternalRepos/etl/src/ivector.h:448:18:   required from 'void etl::ivector<T>::clear() [with T = Config::foo()::AClass&]'
Config/ConfigurationManager.cpp:54:11:   required from here
Config/../../../../ExternalRepos/etl/src/ivector.h:818:15: error: using invalid field 'etl::ivector<T>::p_buffer'
       p_buffer[--current_size].~T();
               ^
In file included from Config/../../../../ExternalRepos/etl/src/vector.h:38:0,
                 from Config/ConfigurationManager.cpp:6:
Config/../../../../ExternalRepos/etl/src/ivector.h:383:10: error: 'void etl::ivector<T>::assign(TIterator, TIterator) [with TIterator = Config::foo()::AClass; T = Config::foo()::AClass&]', declared using local type 'Config::foo()::AClass', is used but never defined [-fpermissive]
     void assign(TIterator first, TIterator last)
          ^

Performance benchmarks ETL vs other STL implementations

I just did quick benchmark comparing different implementation of unordered_map, and ETL was the slowest. Do you have benchmarks ETL vs STL, vs EASTL, or something similar?

Code:

	///
	{
		int64_t elapsed = -bx::getHPCounter();

		for (uint32_t ii = 0; ii < numIterations; ++ii)
		{
			typedef etl::unordered_map<uint64_t, uint16_t, numElements> EtlUnorderedMap;
			EtlUnorderedMap map;

			for (uint32_t jj = 0; jj < numElements; ++jj)
			{
				std::pair<EtlUnorderedMap::iterator, bool> ok = map.insert(std::make_pair(uint64_t(jj), uint16_t(jj) ) );
				assert(ok.second);
			}

			for (uint32_t jj = 0; jj < numElements; ++jj)
			{
				bool ok = bx::mapRemove(map, uint64_t(jj) );
				assert(ok);
			}

//			assert(map.size() == 0);
		}

		elapsed += bx::getHPCounter();
		printf("          ETL: %15f\n", double(elapsed) );
	}

Was added here:
https://github.com/bkaradzic/bx/blob/master/tests/handle_bench.cpp

The results were:

      TinyStl:     4534.000000
          STL:     3573.000000
          ETL:     9690.000000 <<<<
HandleHashMap:     1569.000000

I also tried increasing maximum number of elements to 2x in etl::unordered_map but that didn't change results.

Also there might be some issue with erase functionality but didn't look into it.

Problem with unsorted_map using with etl::string

I've tried to create this type of unsorted_map, but it didn't work. It works well if I use std::unordered_map. I use arm-none-eabi-g++ 7.1.0 compiler.

UPD: Not a etl::flat_map below of course — etl::unordered_map. It's typo.

struct Credentials {
    using Key = etl::string<32>;
    using Value = Result::Token;

    Credentials() {
        map.insert(std::pair<Key, Value>("USERNAME", Value::USERNAME));
        map.insert(std::pair<Key, Value>("PASSWORD", Value::PASSWORD));
    }

    etl::flat_map<Key, Value, 2> map;
} credentials;

I get an error during compilation:

In file included from ../lib/etl/iunordered_map.h:47:0,
                 from ../lib/etl/unordered_map.h:38,
                 from ../utils/keepass/AutotypeReader.cpp:6:
../lib/etl/intrusive_forward_list.h: In instantiation of 'class etl::intrusive_forward_list<etl::iunordered_map<etl::string<32>, utils::keepass::AutotypeReader::Result::Data::Key, etl::hash<etl::string<32> >, std::equal_to<etl::string<32> > >::node_t, etl::forward_link<0> >':
../lib/etl/iunordered_map.h:160:47:   required from 'class etl::iunordered_map<etl::string<32>, utils::keepass::AutotypeReader::Result::Data::Key, etl::hash<etl::string<32> >, std::equal_to<etl::string<32> > >'
../lib/etl/unordered_map.h:57:9:   required from 'class etl::unordered_map<etl::string<32>, utils::keepass::AutotypeReader::Result::Data::Key, 2>'
../utils/keepass/AutotypeReader.cpp:24:39:   required from here
../lib/etl/intrusive_forward_list.h:151:38: warning: comparison between 'enum etl::__private_intrusive_links__::forward_link_base<etl::forward_link<0>, 0, 0>::<unnamed>' and 'enum etl::link_option::<unnamed>' [-Wenum-compare]
       COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) ||
                       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/etl/intrusive_forward_list.h:152:38: warning: comparison between 'enum etl::__private_intrusive_links__::forward_link_base<etl::forward_link<0>, 0, 0>::<unnamed>' and 'enum etl::link_option::<unnamed>' [-Wenum-compare]
                       (TLink::OPTION == etl::link_option::CHECKED)) ? etl::count_option::SLOW_COUNT : etl::count_option::FAST_COUNT
                       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../lib/etl/unordered_map.h:38:0,
                 from ../utils/keepass/AutotypeReader.cpp:6:
../lib/etl/iunordered_map.h: In instantiation of 'class etl::iunordered_map<etl::string<32>, utils::keepass::AutotypeReader::Result::Data::Key, etl::hash<etl::string<32> >, std::equal_to<etl::string<32> > >':
../lib/etl/unordered_map.h:57:9:   required from 'class etl::unordered_map<etl::string<32>, utils::keepass::AutotypeReader::Result::Data::Key, 2>'
../utils/keepass/AutotypeReader.cpp:24:39:   required from here
../lib/etl/iunordered_map.h:1237:12: error: 'etl::iunordered_map<TKey, T, THash, TKeyEqual>::key_hash_function' has incomplete type
     hasher key_hash_function;
            ^~~~~~~~~~~~~~~~~

Google mock support?

Hi,

I'm trying to use gmock with ETL. Has anyone got this working?

The following code works for me:

#include "gtest.h"
#include "gmock.h"

#include "etl/src/vector.h"

class GetSomething {
public:
    virtual int get_something(etl::ivector<int> *input) { return (*input)[0]; };
};

class GetSomethingMock : public GetSomething {
public:
    MOCK_METHOD1(get_something, int(etl::ivector<int> *input));
};

using testing::Return;

TEST(SimpleTest, CallWithVector) {
    GetSomethingMock mock;

    etl::vector<int, 5> v;
    v.push_back(10);

    EXPECT_CALL(mock, get_something(&v))
                .Times(1)
                .WillRepeatedly(Return(12));

    EXPECT_EQ(mock.get_something(&v), 12);
}

However, if I change the signature of the get_something function to take an argument by reference, I receive compiler errors:

#include "gtest.h"
#include "gmock.h"

#include "etl/src/vector.h"

class GetSomething {
public:
    virtual int get_something(etl::ivector<int> &input) { return input[0]; };
};

class GetSomethingMock : public GetSomething {
public:
    MOCK_METHOD1(get_something, int(etl::ivector<int> &input));
};

using testing::Return;

TEST(SimpleTest, CallWithVector) {
    GetSomethingMock mock;

    etl::vector<int, 5> v;
    v.push_back(10);

    EXPECT_CALL(mock, get_something(v))
                .Times(1)
                .WillRepeatedly(Return(12));

    EXPECT_EQ(mock.get_something(v), 12);
}

and the output:

In file included from /Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:6:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock.h:61:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:43:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-spec-builders.h:75:
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3748:43: error: calling a private constructor of class 'etl::ivector<int>'
Matcher<T>::Matcher(T value) { *this = Eq(value); }
                                          ^
/Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:28:37: note: in instantiation of member function 'testing::Matcher<etl::ivector<int> &>::Matcher' requested here
    EXPECT_CALL(mock, get_something(v))
                                    ^
/Users/jeremy/Dropbox/code/fw_test/submodules/etl/src/vector.h:959:5: note: declared private here
    ivector(const ivector&);
    ^
In file included from /Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:6:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock.h:61:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:43:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-spec-builders.h:75:
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3743:48: error: call to implicitly-deleted copy constructor of 'internal::EqMatcher<ivector<int> >'
inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3748:40: note: in instantiation of function template specialization 'testing::Eq<etl::ivector<int> >' requested here
Matcher<T>::Matcher(T value) { *this = Eq(value); }
                                       ^
/Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:28:37: note: in instantiation of member function 'testing::Matcher<etl::ivector<int> &>::Matcher' requested here
    EXPECT_CALL(mock, get_something(v))
                                    ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:927:19: note: copy constructor of 'EqMatcher<etl::ivector<int> >' is implicitly deleted because base class 'ComparisonBase<EqMatcher<etl::ivector<int> >, etl::ivector<int>, testing::internal::AnyEq>' has a deleted copy constructor
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
                  ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:922:7: note: copy constructor of 'ComparisonBase<testing::internal::EqMatcher<etl::ivector<int> >, etl::ivector<int>, testing::internal::AnyEq>' is implicitly deleted because field 'rhs_' has an inaccessible copy constructor
  Rhs rhs_;
      ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:895:45: error: field of type 'etl::ivector<int>' has private copy constructor
  explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
                                            ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:930:9: note: in instantiation of member function 'testing::internal::ComparisonBase<testing::internal::EqMatcher<etl::ivector<int> >, etl::ivector<int>, testing::internal::AnyEq>::ComparisonBase' requested here
      : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
        ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3743:48: note: in instantiation of member function 'testing::internal::EqMatcher<etl::ivector<int> >::EqMatcher' requested here
inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
                                               ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3748:40: note: in instantiation of function template specialization 'testing::Eq<etl::ivector<int> >' requested here
Matcher<T>::Matcher(T value) { *this = Eq(value); }
                                       ^
/Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:28:37: note: in instantiation of member function 'testing::Matcher<etl::ivector<int> &>::Matcher' requested here
    EXPECT_CALL(mock, get_something(v))
                                    ^
/Users/jeremy/Dropbox/code/fw_test/submodules/etl/src/vector.h:959:5: note: declared private here
    ivector(const ivector&);
    ^
In file included from /Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:6:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock.h:61:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:43:
In file included from /Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-spec-builders.h:75:
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:905:37: error: field of type 'etl::ivector<int>' has private copy constructor
    explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
                                    ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:898:28: note: in instantiation of member function 'testing::internal::ComparisonBase<testing::internal::EqMatcher<etl::ivector<int> >, etl::ivector<int>, testing::internal::AnyEq>::Impl<etl::ivector<int> &>::Impl' requested here
    return MakeMatcher(new Impl<Lhs>(rhs_));
                           ^
/Users/jeremy/Dropbox/code/fw_test/submodules/googletest/googlemock/include/gmock/gmock-matchers.h:3748:40: note: in instantiation of function template specialization 'testing::internal::ComparisonBase<testing::internal::EqMatcher<etl::ivector<int> >, etl::ivector<int>, testing::internal::AnyEq>::operator Matcher<etl::ivector<int> &>' requested here
Matcher<T>::Matcher(T value) { *this = Eq(value); }
                                       ^
/Users/jeremy/Dropbox/code/fw_test/test/simple_test.cpp:28:37: note: in instantiation of member function 'testing::Matcher<etl::ivector<int> &>::Matcher' requested here
    EXPECT_CALL(mock, get_something(v))
                                    ^
/Users/jeremy/Dropbox/code/fw_test/submodules/etl/src/vector.h:959:5: note: declared private here
    ivector(const ivector&);
    ^
4 errors generated.

Is there any way to get this going? I suppose in the meantime I will just have to only use pass-by-pointer.

Add `reset()` method to `etl::optional`

std::optional provides a convenient reset() method which is not currently available in the etl counterpart.

Currently users must copy a newly constructed instance of etl::optional<T> to achieve the same result.

P.S. Thanks for the great library!

build problems using IAR for ARM

I have run into a few issues:

as previously mentioned identifier i_begin is undefined in transform_n in algorithm.h

I also get undefined identifiers for:
Error[Pe020]: identifier "UINT8_MAX" is undefined etl\smallest.h 255
Error[Pe020]: identifier "UINT16_MAX" is undefined etl\smallest.h 256
Error[Pe020]: identifier "UINT32_MAX" is undefined etl\smallest.h 257
Error[Pe020]: identifier "INT8_MAX" is undefined etl\smallest.h 276
Error[Pe020]: identifier "INT8_MIN" is undefined etl\smallest.h 276
Error[Pe020]: identifier "INT16_MAX" is undefined etl\smallest.h 277
Error[Pe020]: identifier "INT16_MIN" is undefined etl\smallest.h 277
Error[Pe020]: identifier "INT32_MAX" is undefined etl\smallest.h 278
Error[Pe020]: identifier "INT32_MIN" is undefined etl\smallest.h 278

nullptr_t not correctly named when host nullptr is available

Hi,

I've just started to play with this library (OSX using clang), and it seems that I have found a minor issue. In type_traits.h on line 237, it has the following code: is_same<nullptr_t,. However, this assumes that the custom nullptr_t class from nullptr.h is being used; if nullptr is defined on the platform and being included from cstddef (like it is on mine), it needs to be referenced from the std namespace, ie std::nullptr. Changing this reference on line 237 allows my code to compile.

FSM on_exit_state called on the new state instead of the old state

In the Finite State Machine code, when there is a state transition, the on_exit_state function is called after the state has already changed. This means that the on_exit_state is executed for the new state instead of for the old state;

etl/src/fsm.h

Lines 305 to 313 in 88cc021

if (p_next_state != p_state)
{
do
{
p_state = p_next_state;
fsm_helper::on_exit_state(*p_state);
next_state_id = fsm_helper::on_enter_state(*p_state);
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));

I think the state update line 309 and the on_exit_state call on line 310 should be swapped.

need ‘typename’ before ‘etl::iflat_map

I get a compiler error for elt::flat_map. I use arm-none-eabi-g++ 7.1.0 compiler. Etl lib ver is 9.1.4

../libs/etl/flat_map.h:72:13: error: need ‘typename’ before ‘etl::iflat_map<TKey, TMapped, TKeyCompare>::refmap_t::lookup_t’ because ‘etl::iflat_map<TKey, TMapped, TKeyCompare>::refmap_t’ is a dependent scope
typedef refmap_t::lookup_t lookup_t;
^~~~~~~~

Typo in platform.h

There appears to be a typo in platform.h. It looks like a find/replace mistake. Starting at line 69:

// Check to see if the compiler supports nullptr and large character types.
#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER < 1600)) || \
     defined(ETL_COMPILER_KEIL) || \
     defined(ETL_COMPILER_TI_MSP430) || \
     defined(ETL_COMPILER_IAR) || \
     (defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L))
  #define ETL_ETL_NO_NULLPTR_SUPPORT
  #define ETL_ETL_NO_LARGE_CHAR_SUPPORT
#endif

The defines starting with ETL_ETL_ should instead be just ETL_

[enhancement] Support for non-copyable objects

Hi
Etlcpp, like STL, does not support non-copyable objects. One of the solutions is to use pointers in the containers, but the allocation strategy is up to the developer.
It would be a great feature to allow minimal support for such objects, such as insertion, deletion, sorting (when applicable, e.g. in lists), etc.
In my current dev, I need this feature that I achieve by using macro, such as :
#define DECLARE_LIST_OF_OBJ(newTypeName, objType, ctorTypedParams, ctorFormaParams)
template
class newTypeName : public etl::list<objType, SIZE>
{
void emplace_front ctorTypedParams
{
objType* newSlot = RESERVE A SLOT HERE
new (newSlot) objType ctorFormaParams
INSERT SLOT IN LIST \
}
} \

with usage :
DECLARE_LIST_OF_OBJ(TDataND, AnyObjectNotCopyable, (float a, int b, bool c), (a, b, c) );
typedef TDataND<10> DataNC;

Of course, functions like assign, insert, and other copy-based ones won't be usable, but this is acceptable.

From C++11 it is possible with variadic template... but in my case I cannot use C++11. And ETL is developped to be compiled by compilers that don't support it.

Any chances that such support could be added to ETL ?
Regards

Typename cannot be used outside a template declaration

<type_traits.h>
template <> struct make_signed<wchar_t>
  {
    typedef typename etl::conditional<sizeof(wchar_t) == sizeof(int16_t),
                                      int16_t,
                                      etl::conditional<sizeof(wchar_t) == sizeof(int32_t),
                                                              int32_t,
                                                              void>::type>::type type;
  };

When compiled above code in VS2013, I got error C2899 which is not allowed in C++03 but is allowed in C++11. For the compatibility of C ++ 03, it should not use typename here.

etl::type_def<>: Binding a reference to underlying type as TValue &

I have a need to bind a reference to the underlying TValue type of an etl::type_def<> to pass it off to other code. This code is handling serialisation, but that is not important. The binding takes place at construction time of the consumer and the value that I wish to serialise changes (in my case it is a timestamp on a file).

// a dummy example, its a lot more complex
class Consumer
{
public:
    Consumer(int64_t const &val) : m_Value(val) {}

    void SerialiseNow(SomeStream s) 
    {
        // write the current value
        s.Write(m_Value);
    }
private:
    int64_t const &m_Value;
};

// --- later in program
// this is what I want to bind to the consumer

ETL_TYPEDEF(Timestamp, int64_t);

struct SomeDataThatChangesOverTime
{
    Timestamp time;
};

SomeDataThatChangesOverTime someData;

Consumer mySeraliser(someData.time);

// etc...

I can not create my consumer each time I need it (no dynamic memory allocation and other constraints in the design). And I can't implement a direct binding on the type_def<> without a lot of plumbing changes and probably circular dependencies..

Boost provides reference and const reference operators on its equivalent strong typedef, which works for me (used in other places in my code currently as I'm in the middle of transitioning)

// template parameter T is the same as TValue
operator const T & () const {return t; }
operator T & () { return t; }

Can these be added to etl::type_def<>?

Any thoughts?
Thanks,
Ash.

etl::string(const char* origin, size_t sz) bad behavior

The above mentioned constructor is IMO buggy. I am using an etl::string<MSG_SZ> as a holder for messages to show on a screen, which are coming from arbitrary length sources. When the source is shorter than MSG_SZ, copying the contents in this manner results in garbage at the end of the istring buffer, which in turn gives the wrong value for length() and size().

In some cases (when the original buffer may not be properly terminated) the other constructor etl::string(const char*) is not usable, so I have to use this one.

If the actual origin cstring is shorter, the resulting object is filled with the random crap that is in the SRAM after the cstring end, whatever is needed to satisfy the given sz requirement. But we are dealing with c-style strings after all. I believe that duplicating one of these should always end at the \0 terminator, even when a longer size is indicated.

My suggested fix is to replace line 585 in basic_string.h from

while ((first != last) && (current_size != CAPACITY))

to

while ((first != last) && (first != '\0') && (current_size != CAPACITY))

vector of pointer to a class fails to compile

Hi,

I was trying to write a vector of pointers to a class but it fails to compile under VS2015. I'm using this to build my unit tests before putting the code in to XC32 for the PIC.

I have updated my repository to the latest code (5c42b7a), but this also exhibits the error.

class AClass 
{
};

AClass a;
AClass b;

etl::vector<AClass*, 5> v = {&a, &b};

results in

1>c:\ash\git\r4\externalrepos\etl\src\private\ivectorpointer.h(315): error C2440: 'type cast': cannot convert from 'ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass' to 'void *'
1>  c:\ash\git\r4\externalrepos\etl\src\private\ivectorpointer.h(315): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>  c:\ash\git\r4\externalrepos\etl\src\vector.h(200): note: see reference to function template instantiation 'void etl::ivector<T *>::assign<TIterator>(TIterator,TIterator)' being compiled
1>          with
1>          [
1>              T=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass,
1>              TIterator=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *
1>          ]
1>  c:\ash\git\r4\externalrepos\etl\src\vector.h(200): note: see reference to function template instantiation 'void etl::ivector<T *>::assign<TIterator>(TIterator,TIterator)' being compiled
1>          with
1>          [
1>              T=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass,
1>              TIterator=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *
1>          ]
1>  c:\ash\git\r4\firmware\pic32\lib\_unittests\configtests\configloadtests.cpp(111): note: see reference to function template instantiation 'etl::vector<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *,5>::vector<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass*>(TIterator,TIterator)' being compiled
1>          with
1>          [
1>              TIterator=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *
1>          ]
1>  c:\ash\git\r4\firmware\pic32\lib\_unittests\configtests\configloadtests.cpp(111): note: see reference to function template instantiation 'etl::vector<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *,5>::vector<ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass*>(TIterator,TIterator)' being compiled
1>          with
1>          [
1>              TIterator=ConfigTests::ConfigLoadTests::TestETLVectorOfPointers::AClass *
1>          ]

I get a similar error with XC32 (PIC32 compiler based on GCC).

Config/../../../../ExternalRepos/etl/src/private/ivectorpointer.h: In instantiation of 'void etl::ivector<T*>::assign(TIterator, TIterator) [with TIterator = Config::foo()::AClass*; T = Config::foo()::AClass]':
In file included from Config/../../../../ExternalRepos/etl/src/ivector.h:904:0,
                 from Config/../../../../ExternalRepos/etl/src/vector.h:38,
                 from Config/ConfigurationManager.cpp:6:
Config/../../../../ExternalRepos/etl/src/vector.h:200:38:   required from 'etl::vector<T*, MAX_SIZE_>::vector(TIterator, TIterator) [with TIterator = Config::foo()::AClass*; T = Config::foo()::AClass; long unsigned int MAX_SIZE_ = 5ul]'
Config/ConfigurationManager.cpp:52:38:   required from here
Config/../../../../ExternalRepos/etl/src/private/ivectorpointer.h:315:34: error: invalid cast from type 'Config::foo()::AClass' to type 'void*'
         p_buffer[current_size++] = (void*)*first++;

Install guidelines

Hi,

Is there any simple guidelines to build and use the ETL Library.

Regards
Hari

master branch doesn't compile

Hi John,

I've just updated to the latest master and I'm getting errors on Microchip XC32 1.42 (basically GCC). Not sure if it is an issue with my standard library, or something funky with the merge you did.

There seems to be a file merge marker at the end of src\algorithm.h.

After I edited that out, then I get a series of errors on the is_input_iterator, is_output_iterator, is_bidirectional_iterator and is_random_iterator templates.

specifically I'm seeing:

../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:46:111: error: type/value mismatch at argument 1 in template parameter list for 'template<class T1, class T2> struct etl::is_same'
     static const bool value = etl::is_same<std::iterator_traits<T>::iterator_category, std::input_iterator_tag>::value;
                                                                                                               ^
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:46:111: error:   expected a type, got 'std::iterator_traits<_Iter>::iterator_category'
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:52:112: error: type/value mismatch at argument 1 in template parameter list for 'template<class T1, class T2> struct etl::is_same'
     static const bool value = etl::is_same<std::iterator_traits<T>::iterator_category, std::output_iterator_tag>::value;
                                                                                                                ^
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:52:112: error:   expected a type, got 'std::iterator_traits<_Iter>::iterator_category'
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:58:113: error: type/value mismatch at argument 1 in template parameter list for 'template<class T1, class T2> struct etl::is_same'
     static const bool value = etl::is_same<std::iterator_traits<T>::iterator_category, std::forward_iterator_tag>::value;
                                                                                                                 ^
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:58:113: error:   expected a type, got 'std::iterator_traits<_Iter>::iterator_category'
../Lib/BSGStream/../../../../ExternalRepos/etl/src/iterator.h:64:119: error: type/value mismatch at argument 1 in template parameter list for 'template<class T1, class T2> struct etl::is_same'
     static const bool value = etl::is_same<std::iterator_traits<T>::iterator_category, std::bidirectional_iterator_tag>::value;
        

Supported platforms and compilers

The README.txt states "Any help porting the library to work under different platforms and compilers would be gratefully received." but I was not able to figure out what platforms and compilers are supported already and what portings you or the community prioritize as "most important".

problem with alignment on platforms that don't support int8_t

working on a TI platform that does not support an 8-bit data type I get errors such as:

"alignment.h", line 99: error:
identifier "int8_t" is undefined
typedef typename private_alignment::type_with_alignment_helper<ALIGNMENT, int8_t, int16_t, int32_t, int64_t, float, double, void*>::type type;

this is the offending template:

template <const size_t ALIGNMENT>
class type_with_alignment
{
public:

  typedef typename __private_alignment__::type_with_alignment_helper<ALIGNMENT, int8_t, int16_t, int32_t, int64_t, float, double, void*>::type type;
};

for now I have defined uint8_t=uint16_t

there should probably be a check based on your ETL_8BIT_SUPPORT macro

[enhancement] : set/map/??? fast clear

Hi
I noticed on etl::set than calling clear() gently destroys all items one after another. For POD types, this is not necessary, a simple reset would be enough, and faster.
It applies to set at least, maybe to other containers?
Regards
Damien

Compiler issues w/ VS2013

Hi John,

Thanks for your work with this project. It's a bit young, but I like the direction it appears to be heading and it seems like it could be a nice fit for me and some of my peers.

I'm having issues building with VS2013 and am curious if that is meant to build in that environment or only VS2015 & VS2017. I get the following 3 build errors in Visual Studio 2013 (after updating to use the V120 compiler):

  1. In src\power.h, it is looking for a declaration of uint64_t and not finding it. I am able to resolve by adding #include <stdint.h>, although that may not be the preferred way to go.
  2. In src\private\pvoidvector.h, it is not liking typename on line 75. This seems to be the same issue as one you fixed days back.
  3. In test\test_string_u16.cpp and test_string_u32.cpp, it doesn't like the STR macros (lines 40 in both). It doesn't like U or u (yield error C2065: 'u' : undeclared identifier).

I have fixes for 1 & 2, but am not familiar with Git enough to issue the right Git request for you to review and possibly merge if it makes sense (hence I'm opening an issue to notify you instead). It gives me a permission error when I try a "pull request", but perhaps I'm doing that incorrectly.

I don't yet have an answer for #3 yet (other than to exclude those 2 test files from the build). I don't understand the various 16bit and 32bit string variants to know if there is even a way to fix this with VS2013.

Perhaps of bigger concern, what is the best way to observe master functioning (without modifications). I'm not helping my cause by using VS2013, but I'm an embedded guy who doesn't update my Microsoft tools every year. If there's a quick start guide to get my setup configured the way you test, that would be awesome. I have a team of colleagues who are evaluating ETL as a potential replacement for our present home grown equivalent, but we'd like to know the PC test infrastructure can be built and run ideally without any modifications. Our embedded targets are typically ARM STM32s (using IAR tools) with the occasionally TI DSP (using CCS tools). I see the IAR support is very rough, we'd be willing to help beef that up a bit if we can convince ourselves that this library is in a stable state more often than not.

I'm curious about the Microsoft command line VS option (http://landinghub.visualstudio.com/visual-cpp-build-tools). I haven't looked into that much yet, but may peek as a possible resolution to my VS2013 woes. I'm only looking for a way to test what is checked in (and to possibly verify any fix I might propose before I issue a pull request back to master).

Thanks,

-Jeremy Erdmann

Too many warnings with -Wall in GCC

I just tried to use library with my project but it produces way too many warnings. Luckily there are only for types of warnings, but many instances of them. If these files were .cpp files I would just suppress these warnings for compilation, but because they are in .h files it should be fixed so suppression doesn't affect user code.

-Wundef

etl/intrusive_forward_list.h:935:5: warning: "_DEBUG" is not defined [-Wundef]

#if _DEBUG should be replaced with #if defined(_DEBUG) && _DEBUG

-Wshadow

etl/function.h:204:7: warning: declaration of ‘p_function’ shadows a member of ‘etl::function<void, void>’ [-Wshadow]
       : p_function(p_function)
       ^
../../../../bx/include/etl/function.h:219:24: note: shadowed declaration is here
     void (*p_function)(); ///< Pointer to the function.

This warning is available also in VS2015 by default (not sure why you're not seeing it).

-Wstrict-aliasing

etl/hash.h:369:45: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         return *reinterpret_cast<size_t*>(&v);

This can be fixed by casting through union.

-Wunused-parameter

etl/exception.h:65:47: warning: unused parameter ‘file’ [-Wunused-parameter]
     exception(string_type reason, string_type file, numeric_type line)

This is due to #ifdef, parameters should be just referenced.

etl::set : lower_bound does not behave as stl::set::lower_bound

In test_set, create a test that use (in pseudocode) :
etl::set<int, 10> etlset;
and
stl::set stlset;
both with values {0, 2, 4, 6, 8, 10, 12, 14, 16, 18}

with i in {1, 3, 5, 7, 9, 11, 13, 15, 17} :
stlset.lower_bound(i) != etlset.lower_bound(i)

As result, etl::set::equal_range != stl::set::equal_range

Damien

etl don't build under platformio for Arduino

I have upgraded from version 9.6.1 to 10.3.2 today and i've got some compiler errors:

In etl/src/platform.h, error on #include "etl_profile.h",
i replace it by #include "etl_arduino.h".

In etl/src/c/ecl_timer.h, error on #include "ecl_user.h"

Is this a problem or did I make a mistake?
Thanks for help.

Cheers

Build with IAR failed

Hi,

When I built etl iar project, it failed and give message list below:
IAR version: IAR Embedded Workbench for ARM, 7.40.2.8570
How to fix this problem? Thanks a lot.

Building configuration: etl - Debug
Updating build tree...
test_compile.cpp
Error[Pe065]: expected a ";" C:\01.Projets\03.RefCodes\etl\algorithm.h 296
Error[Pe020]: identifier "n" is undefined C:\01.Projets\03.RefCodes\etl\algorithm.h 298
Error[Pe065]: expected a ";" C:\01.Projets\03.RefCodes\etl\algorithm.h 323
Error[Pe020]: identifier "n" is undefined C:\01.Projets\03.RefCodes\etl\algorithm.h 325
Error[Pe065]: expected a ";" C:\01.Projets\03.RefCodes\etl\algorithm.h 354
Error[Pe020]: identifier "n" is undefined C:\01.Projets\03.RefCodes\etl\algorithm.h 356
Error[Pe065]: expected a ";" C:\01.Projets\03.RefCodes\etl\algorithm.h 381
Error[Pe020]: identifier "n" is undefined C:\01.Projets\03.RefCodes\etl\algorithm.h 383
Warning[Pe940]: missing return statement at end of non-void function "etl::io_port_rw<T, ADDRESS>::iterator::operator=" C:\01.Projets\03.RefCodes\etl\io_port.h 76
Error[Pe519]: class "etl::crc8_ccitt" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 188
Error[Pe519]: class "etl::crc8_ccitt" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 189
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 189
Error[Pe519]: class "etl::crc16" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 191
Error[Pe519]: class "etl::crc16" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 192
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 192
Error[Pe519]: class "etl::crc16_ccitt" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 194
Error[Pe519]: class "etl::crc16_ccitt" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 195
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 195
Error[Pe519]: class "etl::crc16_kermit" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 197
Error[Pe519]: class "etl::crc16_kermit" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 198
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 198
Error[Pe519]: class "etl::crc32" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 200
Error[Pe519]: class "etl::crc32" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 201
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 201
Error[Pe519]: class "etl::crc64_ecma" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 203
Error[Pe519]: class "etl::crc64_ecma" may not have a template argument list C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 204
Error[Pe276]: name followed by "::" must be a class or namespace name C:\01.Projets\03.RefCodes\etl\test\test_compile.cpp 204
Error while running C/C++ Compiler

Total number of errors: 26
Total number of warnings: 1

Ambiguous string, vector, etc. realizations for byte coping purpose

If you have some object of type string and you try to make memcpy of it, you find out that method data() of copied obj returns a wrong pointer to the buffer. It happens because of the string class stores the buffer's pointer separately in the base class but while copying the real address of the buffer is changed. It can be critical for some embedded purposes.

Dead assignment in list.h

Found with scan-build:

etl/src/list.h:195:7: warning: Value stored to 'p_node' is never read
      p_node = p_node->previous;
      ^        ~~~~~~~~~~~~~~~~

Created Slack group

I have created a Slack group to better support the ETL.
You can find it here

EDIT: Updated link.

ETL_DEBUG should not be defined in release builds

platform.h defines ETL_DEBUG to 1 or 0
all the places that check for ETL_DEBUG use #if defined(ETL_DEBUG)

The result is that assertions intended for debug builds only are always enabled.
Not sure what the original intent was, but its probably just easiest to change platform.h to something like the following.

#if defined(_DEBUG) || defined(DEBUG)
  #define ETL_DEBUG
#endif

Here are the changes to platform.h for IAR version 8 and above...

// Check to see if the compiler supports nullptr and large character types.
#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER < 1600)) ||
defined(ETL_COMPILER_KEIL) ||
defined(ETL_COMPILER_TI_MSP430) ||
(defined(ETL_COMPILER_IAR) && (VER < 800)) ||
(defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L))
#define ETL_NO_NULLPTR_SUPPORT
#define ETL_NO_LARGE_CHAR_SUPPORT
#endif

type_def.h: 'explicit' keyword on user-defined conversions is a C++11 feature.

A recent change to type_def.h made the user-defined conversion of tye_def objects explicit. While I agree with this principle, and would love to have it persist, explicit user-defined conversions are a feature of C++11, and my C++03 compiler is complaining.

Would it be possible to revert this change to remain compatible with C++03?

Another option I've seen used before is using the preprocessor to add C++11 features when compilers support them:

#if defined(__cplusplus) && __cplusplus >= 201103L
  #define EXPLICIT_CONVERSION explicit
#else
  #define EXPLICIT_CONVERSION
#endif
//...
EXPLICIT_CONVERSION operator TValue() const

[enhancement] : running tests on target platform (i.e. up to C++03 compatible)

Hi
As a paranoid developer, I need to compile and run unit tests on my target to ensure compatibility with OS, tool suite, etc. . Unfortunately, tests are not C++03 compatible. So I have to modify all required tests to do so.
It would be great to update tests so that they can be run on target as well.
Regards

UINT8_MAX, INT8_MAX not supported for TI C2000 targets

The C2000 targets don't support 8 bit types. This shows up when smallest.h is included ( for example in bitset ).

I changed UINT8_MAX to UINT_LEAST8_MAX, INT8_MAX to INT_LEAST8_MAX, and INT8_MIN to INT_LEAST8_MIN in smallest.h.

  //***************************************************************************
  /// Template to determine the smallest unsigned int type that can contain the
  /// specified unsigned value.
  /// Defines 'type' which is the type of the smallest unsigned integer.
  ///\ingroup smallest
  //***************************************************************************
  template <const uintmax_t VALUE>
  struct smallest_uint_for_value
  {
  private:

    // Determines the index of the best unsigned type for the required value.
    static const int TYPE_INDEX = ((VALUE > UINT_LEAST8_MAX)  ? 1 : 0) +
                                  ((VALUE > UINT16_MAX) ? 1 : 0) + 
                                  ((VALUE > UINT32_MAX) ? 1 : 0);

  public:

    typedef typename __private_smallest__::best_fit_uint_type<TYPE_INDEX>::type type;
  };

  //***************************************************************************
  /// Template to determine the smallest int type that can contain the
  /// specified signed value.
  /// Defines 'type' which is the type of the smallest signed integer.
  ///\ingroup smallest
  //***************************************************************************
  template <const intmax_t VALUE>
  struct smallest_int_for_value
  {
  private:

    // Determines the index of the best signed type for the required value.
    static const int TYPE_INDEX = (((VALUE > INT_LEAST8_MAX)  || (VALUE < INT_LEAST8_MIN))  ? 1 : 0) +
                                  (((VALUE > INT16_MAX) || (VALUE < INT16_MIN)) ? 1 : 0) +
                                  (((VALUE > INT32_MAX) || (VALUE < INT32_MIN)) ? 1 : 0);

  public:

    typedef typename __private_smallest__::best_fit_int_type<TYPE_INDEX>::type type;
  };

etl::ilist::sort does not preserve equivalent nodes order

when sorting a list with some equal element, e.g. (list of ints, with operator<)
5, 15, 10 (a), 10 (b), 10 (c), 20
the result is
5, 10 (c), 10 (b), 10 (a), 15, 20
instead of
5, 10 (a), 10 (b), 10 (c), 15, 20

where 10 (a) denotes the int value 10 with address a

in ilist.h (on older version, I'm currently updating) replacing
else if (compare(*i_left, *i_right)
by
else if (!compare(*i_right, *i_left)

solves the problem

Cheers

Usage of c++11 std::nullptr_t and std::alignment_of

Hi,

I'm trying to compile etl as a static library in Ti Code Composer Studio (Ti compiler v16.9.2.LTS), but I get the following errors in the src tree;

Description                                       Resource            Path       Location   Type
#136 namespace "std" has no member "nullptr_t"    type_traits.h       /etl/src   line 212   C/C++ Problem
#20 identifier "nullptr" is undefined             error_handler.cpp   /etl/src   line 37    C/C++ Problem
#918 alignment_of is not a template               type_traits.h       /etl/src   line 388   C/C++ Problem

Both the std::nullptr_t and std::alignment_of seem to be newly introduced in c++11 (which is not yet supported by this compiler flavor, only c++03).

Cannot instantiate container with object (etl::set, maybe more)

Using "key_value_parameter_t&" make it impossible to use object in etl::set. As key_value_parameter_t is derived from etl::parameter_type, when a reference is required (with an object), it is automatically used. Removing "&" solves the problem.
I did it in etl::set, but the problem might exist elsewhere (I am not a contributor, so I did my modifications locally)

iflat_map::const_iterator invalidates const correctness

In commit 4b84cc9 Iterator classes were added to etl::iflat_map. The const_iterator class defined inside iflat_map contains operator overloads which invalidate the const_iterator's const correctness, specifically:

etl/src/iflat_map.h

Lines 251 to 264 in a3d51f1

pointer operator &()
{
return etl::addressof(*(*ilookup));
}
const_pointer operator &() const
{
return etl::addressof(*(*ilookup));
}
pointer operator ->()
{
return etl::addressof(*(*ilookup));
}

Removing the reference and pointer overloads fixes the issue.

Container destructor does not call item destructors

It's very serious bug in every etl container.

#include <iostream>
#include <vector.h>

class item_t {
    item_t(const item_t&);
    item_t& operator=(const item_t&);
public:
    item_t() {
        std::cout << "item_t::item_t()" << std::endl;
    }
    ~item_t() {
        std::cout << "item_t::~item_t()" << std::endl;
    }
};

int main() {
    { // vector scope
        etl::vector<item_t, 10> v;
        v.push_back();
        v.push_back();
    }
    return 0;
}

// terminal output:
// item_t::item_t()
// item_t::item_t()
// Program ended with exit code: 0

error: '::memchr' has not been declared

Using the release version 8.2.0, the following file cannot be compiled with g++-5 -Ietl-8.2.0/src testetl.cpp -o testetl -std=c++11 using g++-5 (Homebrew gcc5 5.4.0) 5.4.0 on macOS 10.12.1.

#include <vector.h>
#include <string.h>

int main()
{
    return 0;
}

Errors:

In file included from etl-8.2.0/src/ibasic_string.h:39:0,
                 from etl-8.2.0/src/basic_string.h:38,
                 from etl-8.2.0/src/string.h:35,
                 from testetl.cpp:2:
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:75:11: error: '::memchr' has not been declared
   using ::memchr;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:76:11: error: '::memcmp' has not been declared
   using ::memcmp;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:77:11: error: '::memcpy' has not been declared
   using ::memcpy;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:78:11: error: '::memmove' has not been declared
   using ::memmove;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:79:11: error: '::memset' has not been declared
   using ::memset;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:80:11: error: '::strcat' has not been declared
   using ::strcat;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:81:11: error: '::strcmp' has not been declared
   using ::strcmp;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:82:11: error: '::strcoll' has not been declared
   using ::strcoll;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:83:11: error: '::strcpy' has not been declared
   using ::strcpy;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:84:11: error: '::strcspn' has not been declared
   using ::strcspn;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:85:11: error: '::strerror' has not been declared
   using ::strerror;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:86:11: error: '::strlen' has not been declared
   using ::strlen;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:87:11: error: '::strncat' has not been declared
   using ::strncat;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:88:11: error: '::strncmp' has not been declared
   using ::strncmp;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:89:11: error: '::strncpy' has not been declared
   using ::strncpy;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:90:11: error: '::strspn' has not been declared
   using ::strspn;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:91:11: error: '::strtok' has not been declared
   using ::strtok;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:92:11: error: '::strxfrm' has not been declared
   using ::strxfrm;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:93:11: error: '::strchr' has not been declared
   using ::strchr;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:94:11: error: '::strpbrk' has not been declared
   using ::strpbrk;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:95:11: error: '::strrchr' has not been declared
   using ::strrchr;
           ^
/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0/cstring:96:11: error: '::strstr' has not been declared
   using ::strstr;
           ^

The same errors occur with GCC 4.9.3 and GCC 6.2.0 with the same compiler flags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.