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


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

Re: std::copy with std::ostream_iterator<std::array...>

Newsgroups comp.lang.c++
Date 2020-01-05 10:56 -0800
References <qukdjv$fco$1@dont-email.me> <slrn3flsr121tl.4k8.ike@sdf.lonestar.org> <qusu17$ld9$1@dont-email.me> <slrnr14aeq.9in.grahn+nntp@frailea.sa.invalid>
Message-ID <2fa235df-fa7d-47f7-b7aa-5bc16f0e2114@googlegroups.com> (permalink)
Subject Re: std::copy with std::ostream_iterator<std::array...>
From Öö Tiib <ootiib@hot.ee>

Show all headers | View raw


On Sunday, 5 January 2020 20:24:38 UTC+2, Jorgen Grahn  wrote:
> On Sun, 2020-01-05, Ralf Goertz wrote:
> > Am Sat, 4 Jan 2020 21:46:28 -0000 (UTC)
> > schrieb Ike Naar <ike@sdf.lonestar.org>:
> >
> >> On 2020-01-02, Ralf Goertz <me@myprovider.invalid> wrote:
> >> > struct Foo {
> >> >     int i,j;
> >> >     bool operator<(const struct Foo &r) const { //needed for set
> >> >         if (i<r.i) return true;
> >> >         return j<r.j;  
> >> 
> >> This looks suspect.
> >> Do you want (2,1) to be less than (1,2) ? if you want to define a
> >> lexicographical order on (i,j), the comparison should be
> >> 
> >>   return i<r.i || (i==r.i && j<r.j);
> >
> > Yeah, I know.
> 
> I don't know why, but I feel safer defining it like this:
> 
>     bool operator<(const struct Foo &r) const {
>        if (i==r.i) return j < r.j;
>        return i < r.i;
>     }
> 
> Another option would be std::make_pair, and comparing the pairs.

Funny. I checked that most usual in my code is that pattern:

    return (l.a != r.a) ? l.a < r.a
         : (l.b != r.b) ? l.b < r.b
         : (l.c != r.c) ? l.c < r.c
         : (l.d != r.d) ? l.d < r.d
         : l.e < r.e;

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


Thread

std::copy with std::ostream_iterator<std::array...> Ralf Goertz <me@myprovider.invalid> - 2020-01-02 10:37 +0100
  Re: std::copy with std::ostream_iterator<std::array...> Paavo Helde <myfirstname@osa.pri.ee> - 2020-01-02 12:27 +0200
  Re: std::copy with std::ostream_iterator<std::array...> Bo Persson <bo@bo-persson.se> - 2020-01-02 12:26 +0100
    Re: std::copy with std::ostream_iterator<std::array...> Ralf Goertz <me@myprovider.invalid> - 2020-01-02 16:10 +0100
      Re: std::copy with std::ostream_iterator<std::array...> James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-02 23:13 -0500
        Re: std::copy with std::ostream_iterator<std::array...> Ralf Goertz <me@myprovider.invalid> - 2020-01-03 07:49 +0100
          Re: std::copy with std::ostream_iterator<std::array...> James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-03 08:30 -0500
      Re: std::copy with std::ostream_iterator<std::array...> Bo Persson <bo@bo-persson.se> - 2020-01-03 15:09 +0100
  Re: std::copy with std::ostream_iterator<std::array...> Ike Naar <ike@sdf.lonestar.org> - 2020-01-04 21:46 +0000
    Re: std::copy with std::ostream_iterator<std::array...> Ralf Goertz <me@myprovider.invalid> - 2020-01-05 16:06 +0100
      Re: std::copy with std::ostream_iterator<std::array...> Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-05 18:24 +0000
        Re: std::copy with std::ostream_iterator<std::array...> Öö Tiib <ootiib@hot.ee> - 2020-01-05 10:56 -0800
          Re: std::copy with std::ostream_iterator<std::array...> Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-05 19:55 +0000

csiph-web