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

  • Home
  • SEARCH
  • 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 6336247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:01:03+00:00 2026-05-24T19:01:03+00:00

I have to fill a std::vector with elements of type struct MHD_OptionItem . This

  • 0

I have to fill a std::vector with elements of type struct MHD_OptionItem.
This struct have this implementation:

struct MHD_OptionItem
{
    enum MHD_OPTION option;
    intptr_t value;
    void *ptr_value;
 };

I have tried this way:

 vector<struct MHD_OptionItem> iov;
 if(...)
     iov.push_back({ MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL });
 if(...)
     iov.push_back({ MHD_OPTION_CONNECTION_TIMEOUT, connectionTimeout });
 [....]

but the g++ compiler, as expected, says to me:

warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x

I know that I can initialize a temporary struct and then pass it to the vector, but this method seems to me to be inefficient and not so elegant.

I can’t change the struct inserting a constructor because this is not my code but a library included.

There is an elegant way to do this without using c++0x syntax?

  • 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-24T19:01:04+00:00Added an answer on May 24, 2026 at 7:01 pm

    Assuming you cannot change the struct or you want to leave it a POD:

    void f()
    {
        struct {
            MHD_OptionItem operator ()(enum MHD_OPTION opt, intptr_t val, void *ptr = 0) {
                MHD_OptionItem x = {opt, val, ptr};
                return x;
            }
        } gen;
    
         vector<struct MHD_OptionItem> iov;
         if(...)
             iov.push_back(gen(MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL));
         if(...)
             iov.push_back(gen(MHD_OPTION_CONNECTION_TIMEOUT, connectionTimeout));
         [....]
    }
    

    Another solution:

        struct Gen : MHD_OptionItem {
            Gen(enum MHD_OPTION opt, intptr_t val, void *ptr = 0) {
                option = opt;
                value = val;
                ptr_value ptr;
            }
        };
    
         vector<struct MHD_OptionItem> iov;
         if(...)
             iov.push_back(Gen(MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL));
         if(...)
             iov.push_back(Gen(MHD_OPTION_CONNECTION_TIMEOUT, connectionTimeout));
         [....]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a vector std::vector<std::string> lines. I fill this vector up, and can
I have this function: void RegMatrix::MatrixInit(int numRow,int numCol, std::vector<double> fill) { do something; }
I have a GridView what I fill through a LINQ expression. Something like this:
I'm having trouble getting MPI_Gatherv to work with a std::vector. I have written a
I have a std::vector that I know will never have to grow--it will always
In the program, I have to create a function to fill elements in an
I have typedef std::queue<MyObject*> InputQueue; std::vector<InputQueue> inp_queue; Now what I want to do is
I have to fill a combobox with month in English: January, February, etc. I
I have a DataContract class that I have to fill by values from the
I have a pattern (.png image 4x4px) and have to fill the layout with

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.