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


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

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

From Ralf Goertz <me@myprovider.invalid>
Newsgroups comp.lang.c++
Subject std::copy with std::ostream_iterator<std::array...>
Date 2020-01-02 10:37 +0100
Organization A noiseless patient Spider
Message-ID <qukdjv$fco$1@dont-email.me> (permalink)

Show all headers | View raw


Hi,

I don't get the problem in the following program. If I use 

using Coords=Foo;

everything is okay but with 

using Coords=std::array<int,2>

I get bombarded with (for me) undecipherable template errors originating
from the std::copy line. Note that without that line it works for both
types, so the operator overload "<<" should not be the problem.

What ist going on

#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <set>

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;
    }
};

std::ostream & operator<<(std::ostream &o,const std::array<int,2> &c) {
    return o<<'('<<c[0]<<','<<c[1]<<')';
}

std::ostream & operator<<(std::ostream &o,const Foo &c) {
    return o<<'('<<c.i<<','<<c.j<<')';
}
                    
using Coords=Foo;  //this works
//using Coords=std::array<int,2>; //this doesn't

int main() {
    std::set<Coords> ls;
    ls.insert(Coords({47,11}));
    std::cout<<*ls.begin()<<std::endl;
    std::copy(ls.cbegin(),ls.cend(),std::ostream_iterator<Coords>(std::cout," ")); //Compile error with array
    std::cout<<"\n";
}

Back to comp.lang.c++ | Previous | Next — 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