Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #80683

Re: [ #include <stack> ] What's the difference?

From Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: [ #include <stack> ] What's the difference?
Date 2021-07-06 21:59 -0700
Organization A noiseless patient Spider
Message-ID <sc3cas$g0o$1@dont-email.me> (permalink)
References <sa0877$3h9$1@dont-email.me> <savqan$4de$1@dont-email.me> <sb2t4f$a4d$1@dont-email.me> <sc2c64$ut5$1@dont-email.me> <sc2vbg$gr4$1@dont-email.me>

Show all headers | View raw


On 7/6/2021 6:17 PM, James Kuyper wrote:
> On 7/6/21 3:50 PM, Andrey Tarasevich wrote:
>> On 6/24/2021 2:23 PM, James Kuyper wrote:
>>> ...
>>> What more do you need to know about the the type of myStack that you
>>> don't already know?
>>> The subject line says "#include <stack>", so you can reasonably presume
>>> from its name that myStack is of type std::stack<T, Container> for some
>>> values of T and Container.
>>
>> I need to know what `T` is. I need to know whether `myStack` holds
>> `int`s, or `myStack` holds something else, perhaps some non-trivial,
>> unrelated, possibly "heavy" type, which just happens to be implicitly
>> convertible from `int`.
>>
>> For `T == int` the difference between the variants would be purely
>> conceptual, without any practical consequences.
>>
>> For a "heavy" `T` the difference between these two variants can be
>> substantial. `push` would construct a temporary followed by two moves
>> from it into a new container entry, while `emplace` would construct a
>> new container entry in-place from the twice-forwarded `30`.
> 
> That doesn't make the question "meaningless", nor does it prevent the
> question from having an answer. The question can be answered in full by
> quoting what the standard says about std::stack<T, Container>::push()
> and emplace(). The ways in which the behavior depends upon T and
> Containter are completely determined by what the standard says about
> those functions, directly or indirectly. The "significant difference"
> between those two functions that the OP was talking about consists
> entirely of the differences between what the standard says about them,
> along with the T-dependent implications of those differences.

This is just another way of saying that every C++ question can be 
answered by a copy-paste of a link to the language standard. True, but 
not very useful. Linking to a specific section does not change much from 
qualitative point of view.

I'm confident that the OP meant to ask a very specific question and 
expected to receive a very specific answer. Namely, the OP probably 
assumed that we'll immediately "deduce" `myStack` as `std::stack<int>`. 
I'm just pointing out the fact that this is an unjustified assumption. 
When asking questions, don't assume. Strive to provide all relevant 
information.

Yes, sometimes it is difficult to properly include every important 
detail at the first try. But what we got here is ridiculously insufficient.

-- 
Best regards,
Andrey Tarasevich

Back to comp.lang.c++ | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[ #include <stack> ] What's the difference? SIMON <invalid@invalid.invalid> - 2021-06-11 17:55 +0000
  Re: [ #include <stack> ] What's the difference? SIMON <invalid@invalid.invalid> - 2021-06-11 18:08 +0000
    Re: [ #include <stack> ] What's the difference? scott@slp53.sl.home (Scott Lurndal) - 2021-06-11 18:21 +0000
  Re: [ #include <stack> ] What's the difference? Richard Damon <Richard@Damon-Family.org> - 2021-06-11 14:29 -0400
  Re: [ #include <stack> ] What's the difference? Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-11 20:35 +0200
  Re: [ #include <stack> ] What's the difference? Manfred <noname@add.invalid> - 2021-06-12 20:06 +0200
    Re: [ #include <stack> ] What's the difference? Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-12 20:12 +0200
    Re: [ #include <stack> ] What's the difference? MrSpook_mlauoyv4F_@o18rpnvgrx0dq.co.uk - 2021-06-13 08:34 +0000
      Re: [ #include <stack> ] What's the difference? Öö Tiib <ootiib@hot.ee> - 2021-06-13 04:31 -0700
  Re: [ #include <stack> ] What's the difference? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-06-23 10:17 -0700
    Re: [ #include <stack> ] What's the difference? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-06-24 17:23 -0400
      Re: [ #include <stack> ] What's the difference? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-06 12:50 -0700
        Re: [ #include <stack> ] What's the difference? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-06 21:17 -0400
          Re: [ #include <stack> ] What's the difference? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-06 21:59 -0700

csiph-web