Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3871594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:50:20+00:00 2026-05-19T21:50:20+00:00

I have a std::map of Poco::Any which I’m trying to iterate and output to

  • 0

I have a std::map of Poco::Any which I’m trying to iterate and output to a stream but i’m getting a compiler error. My code is below:

map<string, Poco::Any>::const_iterator it;
map<string, Poco::Any>::const_iterator end = _map.end();
map<string, Poco::Any>::const_iterator begin = _map.begin();
for(it = begin; it != end; ++it) {
    const std::type_info &type = it->second.type();

    // compile error here:
    os << "  " << it->first << " : " << Poco::RefAnyCast<type>(it->second) << endl;
}

2 errors on that line:

'type' cannot appear in a constant-expression
no matching function for call to 'RefAnyCast(Poco::Any&)'

UPDATE:

I understand that templates are compile time whereas type() is runtime so won’t work. Thanks for underlining that. Also DynamicAny won’t work because it only accepts types which have DynamicAnyHolder implementations, not ideal. The only rule i’d like to impose on the types is that they have << overloaded.

Below is what i’m currently doing, works to a degree, but only dumps known types, which is not what I’m after.

string toJson() const {
    ostringstream os;
    os << endl << "{" << endl;
    map<string, Poco::Any>::const_iterator end = _map.end();
    map<string, Poco::Any>::const_iterator begin = _map.begin();
    for(map<string, Poco::Any>::const_iterator it = begin; it != end; ++it) {
        const std::type_info &type = it->second.type();
        os << "  " << it->first << " : ";

        // ugly, is there a better way?
        if(type == typeid(int)) os << Poco::RefAnyCast<int>(it->second);
        else if(type == typeid(float)) os << Poco::RefAnyCast<float>(it->second);
        else if(type == typeid(char)) os << Poco::RefAnyCast<char>(it->second);
        else if(type == typeid(string)) os << Poco::RefAnyCast<string>(it->second);
        else if(type == typeid(ofPoint)) os << Poco::RefAnyCast<ofPoint>(it->second);
        else if(type == typeid(ofVec2f)) os << Poco::RefAnyCast<ofVec2f>(it->second);
        else if(type == typeid(ofVec3f)) os << Poco::RefAnyCast<ofVec3f>(it->second);
        //else if(type == typeid(ofDictionary)) os << Poco::RefAnyCast<ofDictionary>(it->second);
        else os << "unknown type";

        os << endl;
    }
    os<< "}" << endl;
    return os.str();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:50:20+00:00Added an answer on May 19, 2026 at 9:50 pm

    Runtime type information cannot be used to instantiate templates. An instance of type_info whose value will only be known when you run the program, doesn’t magically turn into a type like int, std::string or struct FooBar when the compiler is compiling this code.

    I don’t know Poco library, but perhaps you could use their other Any type, DynamicAny (see documentation) which would hopefully allow you to convert the stored value to std::string for outputting:

    os << "  " << it->first << " : " << it->second.convert<std::string>() << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this map which compiles fine in MSVC10 : std::map<std::string, std::ofstream> m_logFiles; But
I have a std::map<std::string, HANDLE> SampleMap which stores HANDLE objects as value. After the
I have a std::map< std::string, std::string> which initialized with some API call. When I'm
Say I have an std::map type which for example is defined as follows. std::map<int,
I have an std::map < std::string, std::string > which is having values added to
I have std::set<std::pair<float,float>> which represents points on map ( 2d , x and y
I have a std::map called 'prompts' which is declared like this: std::map<const int, wstring,
I have some opaque bytes which I want to use in an std::map ,
std::map<any, string> is not working so I wonder if there's another approach to have
I have a std::map which is a private member of a class. One of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.