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

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [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 Source Code

    1. #include <map>
    2. #include <stdint.h>
    3. class Test
    4. {
    5. enum class ENumber
    6. {
    7. Zero, One, Two
    8. };
    9. typedef std::map<uint32_t, ENumber> Map;
    10. static const Map theMap;
    11. };
    12. const Test::Map Test::theMap =
    13. {
    14. { 0, Test::ENumber::Two }
    15. , { 2, Test::ENumber::One }
    16. };
    Display All

    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
  • 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.

    Keep in mind, this is *not* a support forum.
    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 you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • 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

    The post was edited 2 times, last by Achim O. ().

  • 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 Source Code

    1. class Test
    2. {
    3. Test() {
    4. theMap[0] = Test::ENumber::Zero;
    5. theMap[1] = Test::ENumber::One;
    6. theMap[2] = Test::ENumber::Two;
    7. };
    8. enum class ENumber
    9. {
    10. Zero, One, Two
    11. };
    12. typedef std::map<uint32_t, ENumber> Map;
    13. static Map theMap;
    14. };
    Display All


    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.

    Keep in mind, this is *not* a support forum.
    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 you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.