Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

emplace syntax - error fixing:

Featured Replies

Posted

emplace syntax - error fixing
Having this original method:
 

Quote

 

    // store parsed options from src into dest
    // arguments are appended, not overwritten
    // thus for options that can be given once the first stored argument is used
    // and for options that can be given multiple times the argument lists are concatenated
    inline void store(const variables_map& src, variables_map& dest)
    {
        // append values in src to dest
        for (auto& l_p : src)
        {
            if (dest.count(l_p.first))
                for (auto& s : l_p.second.values())
                    dest[l_p.first]._add(s);
            else
                dest.emplace(l_p);
        }
        for (auto& s : src.unrecognized)
            dest.unrecognized.emplace_back(s);
        for (auto& s : src.positional)
            dest.positional.emplace_back(s);
    }

 

 

 

Source code location: https://github.com/cr-marcstevens/sha1_gpu_nearcollisionattacks/blob/master/contrib/program_options.hpp

I am trying this:

    inline void store(const variables_map& src, variables_map& dest)
    {
        // append values in src to dest
        
        // for (po::variables_map::iterator it = vm.begin(); it != vm.end(); it++) {
        // for (auto& l_p : src)
        for (program_options::variables_map::const_iterator l_p = src.begin();
            l_p != src.end(); l_p++)
        {

            //            for each (std::string s in l_p.second.values())
            //{

            if (dest.count(l_p->first))
                //for (auto& s : l_p.second.values())
                  for each (std::string s in l_p->second.values())
                    dest[l_p->first]._add(s);

            // emplace is causing all problems:
            else
                dest.emplace(l_p);

        }
        //for (auto& s : src.unrecognized)
        for each (std::string s in src.unrecognized)
            dest.unrecognized.emplace_back(s);
        //for (auto& s : src.positional)
        for each (detail::parser s in src.positional)
            dest.positional.emplace_back(s);


    }

emplace:
http://www.cplusplus.com/reference/vector/vector/emplace/

variables_map is defined as fallows:
   

Quote

/* stores a map of parsed option.name => parser, as well as unrecognized options, positional arguments */
    struct variables_map
        : public std::map<std::string, detail::parser>
    {
        std::vector<std::string> unrecognized;
        std::vector<detail::parser> positional;
    };
    //using parsed_options = variables_map;

So any help with this emplace would be great.
 

Edited by CodeExplorer

  • Author

I think I got it!!!:

		std::pair <std::string, program_options::detail::parser> NewPair;
		//NewPair = std::make_pair(std::string("lightbulbs"), detail::parser());
		// for creating instance don't use new!
          
        	// emplace is causing all problems:
			else
			{
				NewPair = std::make_pair(l_p->first, l_p->second);
				dest.emplace(NewPair);
			}

Let me know if I am I right!!!
More info:
http://www.cplusplus.com/reference/utility/pair/pair/

https://stackoverflow.com/questions/4207346/how-can-i-traverse-iterate-an-stl-map

 

What's the error you are getting?

The way the original is written looks like it should work fine since the two types for src and dest are the same. So emplace should be taking the l_p entry no issues.

You have to "deref" the iterator:

dest.emplace(*l_p);

 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.