Compile error in SitRepPanel.cpp

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Compile error in SitRepPanel.cpp

#1 Post by Vezzra »

I get the following compile error on OSX:

Code: Select all

/Users/user/SoftwareProjekte/FO/src/UI/SitRepPanel.cpp:137:13: No matching conversion for functional-style cast from 'std::istringstream' (aka 'basic_istringstream<char>') to 'std::istream_iterator<std::string>'
The code section in question is:

Code: Select all

    std::set<std::string> HiddenSitRepTemplateStringsFromOptions() {
        std::set<std::string> result;
        std::string saved_template_string = GetOptionsDB().Get<std::string>("hidden-sitrep-templates");

        std::copy(
            std::istream_iterator<std::string>(std::istringstream(saved_template_string)),
            std::istream_iterator<std::string>(),
            std::inserter(result, result.begin())
        );

        return result;
    }
Line 137 is "std::istream_iterator<std::string>(std::istringstream(saved_template_string)),"

This code section has been added with commit 6944641 ("Enabled saving hidden sitrep templates in config.xml") by Bigjoe.

Bigjoe?

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Compile error in SitRepPanel.cpp

#2 Post by Bigjoe5 »

What version of C++ is your compiler targeting? I wonder if it's a c++ 11 incompatibility, or just MSVC being overly liberal.

Try this:

Code: Select all

        std::istringstream ss(saved_template_string);
        std::copy(
            std::istream_iterator<std::string>(ss),
            std::istream_iterator<std::string>(),
            std::inserter(result, result.begin())
        )
Warning: Antarans in dimensional portal are closer than they appear.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Compile error in SitRepPanel.cpp

#3 Post by Geoff the Medio »

Could you add a comment before that code to clarify what it's doing? Breaking (space) delimited string into single-word strings, presumably?

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Compile error in SitRepPanel.cpp

#4 Post by Bigjoe5 »

Geoff the Medio wrote:Could you add a comment before that code to clarify what it's doing? Breaking (space) delimited string into single-word strings, presumably?
Done.
Warning: Antarans in dimensional portal are closer than they appear.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Compile error in SitRepPanel.cpp

#5 Post by Vezzra »

Bigjoe5 wrote:Try this:

Code: Select all

        std::istringstream ss(saved_template_string);
        std::copy(
            std::istream_iterator<std::string>(ss),
            std::istream_iterator<std::string>(),
            std::inserter(result, result.begin())
        )
That fixed it.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Compile error in SitRepPanel.cpp

#6 Post by Dilvish »

I had the same problem. The fix worked for me as well; I committed it.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Post Reply