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 9319451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:23:18+00:00 2026-06-19T03:23:18+00:00

I think that using emplace(c.end(),_1) would be same as emplace_back(_1) But I am not

  • 0

I think that using emplace(c.end(),_1) would be same as emplace_back(_1)
But I am not understanding why the language designers gave two functions instead of one.
I am assuming I am missing some information.

So what is it that differentiate emplace(c.end(),_1) from emplace_back(_1) ?

  • 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-06-19T03:23:20+00:00Added an answer on June 19, 2026 at 3:23 am

    The big difference is the requirements on the container’s value_type is lessened for vector::emplace_back and deque::emplace_back compared to emplace.

    Speaking for vector and deque only:

    In addition to EmplaceConstructible from args;

    emplace requires MoveInsertable and MoveAssignable, whereas

    emplace_back only requires MoveInsertable.

    For most allocators, including std::allocator, MoveInsertable is the same as MoveConstructible.

    So if you have a type that you want to put into a vector or deque, and it is MoveConstructible, but not MoveAssignable, emplace_back is your friend. It is also likely to be slightly faster, and have slightly smaller code size, but that is a quality-of-implementation issue (not guaranteed by the standard). And the difference is likely to be smaller than you will notice (unless measuring carefully).

    For example, given:

    #include <vector>
    
    struct A
    {
        A() = default;
        A(A&&) = default;
        A& operator=(A&&) = delete;
    };
    

    This compiles:

    int main()
    {
        std::vector<A> v;
        v.emplace_back();
    }
    

    But this does not:

    int main()
    {
        std::vector<A> v;
        v.emplace(v.end()); //  error A is not MoveAssignable
    }
    

    However if I changed:

        A& operator=(A&&) = delete;
    

    to:

        A& operator=(A&&) = default;
    

    then both examples would compile (and run fine).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I am using Adobe Cirrus in my Flex app, but I think that
I think that using Menu key to quit vim's insert mode would be a
I don't think that using .ini or .xml file is a good idea with
I think that this problem can be sorted using reflection (a technology which I'm
I'm using this css file but one thing that is annoying me is the
I think that I'm probably not writing lazily instantiated methods/attributes in the most ruby
[self performSelector:@selector(stopPulling) withObject:nil afterDelay:0.01]; The code is fine. I just think that using NSOperation
I´m working with Raphael, and I think that I´m using it in a way
Some of the people in my project seem to think that using a common
I think that using many little cells is a better idea then rendering one

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.