Sunday, May 20th 2018, 5:24pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Achim O.

Beginner

Date of registration: Sep 13th 2017

Posts: 7

1

Friday, March 23rd 2018, 11:13am

[SOLVED] Cannot compile std::map initialization from initializer list

Good morning,
I am trying to compile the following code (SES 3.34, G++ 6-2017-q2, option -std=c++11 set):

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <map>
#include <stdint.h>

class Test
{
	enum class ENumber
	{
		Zero, One, Two
	};
	
	typedef std::map<uint32_t, ENumber> Map;
	static const Map theMap;
};

const Test::Map Test::theMap = 
{
		{ 0, Test::ENumber::Two }
	, 	{ 2, Test::ENumber::One }
};

and get this error message:

Source code

1
testmap.cpp:23:1: error: could not convert '{{0, Two}, {2, One}}' from '<brace-enclosed initializer list>' to 'const Map {aka const stlpmtx_std::map<unsigned int, Test::ENumber>}'

The code seems correct to me, and it compiles without complaints natively on my Ubuntu PC (g++ 5.4)

Is there a way I can do this with STLport?

Can you point me to a site where the current STLport subset is documented?

Thank you,
Achim

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 1,048

2

Monday, March 26th 2018, 9:22am

Hello Achim,

Thank you for your inquiry.
This should be doable with STLPort.
You can install it using the package manager: Tools->Package Manager...->STLPort library

To make it available in your project open project settings, then Code->Libraries->STLPort Library->set to yes.

Does that work with your setup?

Best regards,
Nino
Please read the forum rules before posting: Forum Rules

Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
Should you be entitled to support contact us per e-mail.
The following contact form can be used for this: https://www.segger.com/about-us/contact-us/


Achim O.

Beginner

Date of registration: Sep 13th 2017

Posts: 7

3

Thursday, March 29th 2018, 9:00am

Hello Nino,
STLport Library Package, Version 1.00 is installed - otherwise I would see "std::map is not a type" or even "map: no such file". It doesn't work.

I do use std::map in my project, but I cannot initialize one this way.

Does it work on your site?

Best regards,
Achim

This post has been edited 2 times, last edit by "Achim O." (Mar 29th 2018, 9:12am)


SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 1,048

4

Thursday, March 29th 2018, 5:26pm

Hello Achim,

The STLPort shipped with ES is only 100% c++98. Some C++11 and 14 extension have been added but not for std::map yet.
So to be able to initialize your map with ES you can do as follows:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Test
{
  Test() {
    theMap[0] = Test::ENumber::Zero;
    theMap[1] = Test::ENumber::One;
    theMap[2] = Test::ENumber::Two;
  };

	enum class ENumber
	{
		Zero, One, Two
	};
	
	typedef std::map<uint32_t, ENumber> Map;
	static Map theMap;
};


We will discuss internally if a std::map extension for c++11 can also be added to support your code. But no promises.

Best regards,
Nino
Please read the forum rules before posting: Forum Rules

Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
Should you be entitled to support contact us per e-mail.
The following contact form can be used for this: https://www.segger.com/about-us/contact-us/