From: Vladimir Grigoriev on 12 Jan 2010 11:00 Another question. When I include std::rel_ops before the main() my code compiles. When I include the operators inside the main the compiler issues errors. May I use using std::rel_ops::operator !=; using std::rel_ops::operator >; using std::rel_ops::operator <=; using std::rel_ops::operator >=; statements inside a code block such a way that the compiler could deduce template arguments? Vladimir Grigoriev c:\program files\microsoft visual studio 8\vc\include\functional(165) : error C2784: 'bool std::operator <=(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const element' c:\program files\microsoft visual studio 8\vc\include\xutility(1858) : see declaration of 'std::operator <=' c:\program files\microsoft visual studio 8\vc\include\functional(164) : while compiling class template member function 'bool std::less_equal<_Ty>::operator ()(const _Ty &,const _Ty &) const' with [ _Ty=element ]
From: Victor Bazarov on 12 Jan 2010 11:49 Vladimir Grigoriev wrote: > Another question. > > When I include std::rel_ops before the main() my code compiles. How do you "include" it? It's not like it's a header... > When I > include the operators inside the main the compiler issues errors. May I use > > using std::rel_ops::operator !=; > > using std::rel_ops::operator >; > > using std::rel_ops::operator <=; > > using std::rel_ops::operator >=; > > statements inside a code block such a way that the compiler could deduce > template arguments? Are those by any chance templates? > > > > Vladimir Grigoriev > > c:\program files\microsoft visual studio 8\vc\include\functional(165) : > error C2784: 'bool std::operator <=(const std::reverse_iterator<_RanIt> > &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template > argument for 'const std::reverse_iterator<_RanIt> &' from 'const element' > c:\program files\microsoft visual studio 8\vc\include\xutility(1858) > : see declaration of 'std::operator <=' > c:\program files\microsoft visual studio > 8\vc\include\functional(164) : while compiling class template member > function 'bool std::less_equal<_Ty>::operator ()(const _Ty &,const _Ty &) > const' > with > [ > _Ty=element > ] > And where is the code? Are we to divine it or read your mind (or, better yet, the mind of your computer)? Please post the code when asking a question about the code and the errors you get from compiling it. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
From: zeromem on 12 Jan 2010 12:26 You probably need to move "#include <utility>" to before "#include <map>" or whatever the master data type file is. On 1/12/2010 8:00 AM, Vladimir Grigoriev wrote: > Another question. > > When I include std::rel_ops before the main() my code compiles. When I > include the operators inside the main the compiler issues errors. May I use > > using std::rel_ops::operator !=; > > using std::rel_ops::operator>; > > using std::rel_ops::operator<=; > > using std::rel_ops::operator>=; > > statements inside a code block such a way that the compiler could deduce > template arguments? > > > > Vladimir Grigoriev > > c:\program files\microsoft visual studio 8\vc\include\functional(165) : > error C2784: 'bool std::operator<=(const std::reverse_iterator<_RanIt> > &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template > argument for 'const std::reverse_iterator<_RanIt> &' from 'const element' > c:\program files\microsoft visual studio 8\vc\include\xutility(1858) > : see declaration of 'std::operator<=' > c:\program files\microsoft visual studio > 8\vc\include\functional(164) : while compiling class template member > function 'bool std::less_equal<_Ty>::operator ()(const _Ty&,const _Ty&) > const' > with > [ > _Ty=element > ] > >
From: Vladimir Grigoriev on 13 Jan 2010 08:41 Victor, the sample code is the following #include "stdafx.h" #include <iostream> #include <functional> #include <algorithm> #include <utility> #define NAME_SIZE 10 struct element { int value; char name[ NAME_SIZE ]; } first_init = { 1, "first" }, second_init = { 1, "second" }; bool operator <( const element &lhs, const element &rhs ) { return ( lhs.value < rhs.value ); } bool operator ==( const element &lhs, const element &rhs ) { return ( ( lhs.value == rhs.value ) && ( std::strcmp( lhs.name, rhs.name ) == 0 ) ); } std::ostream & operator <<( std::ostream &os, const element &rhs ) { os << '{' << rhs.value << ", " << rhs.name << '}'; return ( os ); } int _tmain(int argc, _TCHAR* argv[]) { using std::rel_ops::operator !=; using std::rel_ops::operator >; using std::rel_ops::operator <=; using std::rel_ops::operator >=; element el1 = first_init, el2 = second_init; std::cout << "\nstd::min( " << el1 << ", " << el2 << ", std::less_equal<element>() } = " << std::min( el1, el2, std::less_equal<element>() ) << std::endl; return 0; } Vladimir Grigoriev "Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message news:hii95o$3f6$1(a)news.datemas.de... > Vladimir Grigoriev wrote: >> Another question. >> >> When I include std::rel_ops before the main() my code compiles. > > How do you "include" it? It's not like it's a header... > > > When I >> include the operators inside the main the compiler issues errors. May I >> use >> >> using std::rel_ops::operator !=; >> >> using std::rel_ops::operator >; >> >> using std::rel_ops::operator <=; >> >> using std::rel_ops::operator >=; >> >> statements inside a code block such a way that the compiler could deduce >> template arguments? > > Are those by any chance templates? > >> >> >> >> Vladimir Grigoriev >> >> c:\program files\microsoft visual studio 8\vc\include\functional(165) : >> error C2784: 'bool std::operator <=(const std::reverse_iterator<_RanIt> >> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template >> argument for 'const std::reverse_iterator<_RanIt> &' from 'const element' >> c:\program files\microsoft visual studio >> 8\vc\include\xutility(1858) : see declaration of 'std::operator <=' >> c:\program files\microsoft visual studio >> 8\vc\include\functional(164) : while compiling class template member >> function 'bool std::less_equal<_Ty>::operator ()(const _Ty &,const _Ty &) >> const' >> with >> [ >> _Ty=element >> ] >> > > And where is the code? Are we to divine it or read your mind (or, better > yet, the mind of your computer)? Please post the code when asking a > question about the code and the errors you get from compiling it. > > V > -- > Please remove capital 'A's when replying by e-mail > I do not respond to top-posted replies, please don't ask
From: Igor Tandetnik on 13 Jan 2010 09:03 Vladimir Grigoriev wrote: > Victor, > the sample code is the following > > #include "stdafx.h" > #include <iostream> > #include <functional> > #include <algorithm> > #include <utility> > #define NAME_SIZE 10 > > struct element > { > int value; > char name[ NAME_SIZE ]; > } first_init = { 1, "first" }, second_init = { 1, "second" }; > > bool operator <( const element &lhs, const element &rhs ) > { > return ( lhs.value < rhs.value ); > } > > bool operator ==( const element &lhs, const element &rhs ) > { > return ( ( lhs.value == rhs.value ) && > ( std::strcmp( lhs.name, rhs.name ) == 0 ) ); > } > > std::ostream & operator <<( std::ostream &os, const element &rhs ) > { > os << '{' << rhs.value << ", " << rhs.name << '}'; > return ( os ); > } > > int _tmain(int argc, _TCHAR* argv[]) > { > using std::rel_ops::operator !=; > using std::rel_ops::operator >; > using std::rel_ops::operator <=; > using std::rel_ops::operator >=; > element el1 = first_init, el2 = second_init; > std::cout << "\nstd::min( " << el1 << ", " << el2 > << ", std::less_equal<element>() } = " > << std::min( el1, el2, std::less_equal<element>() ) > << std::endl; > > return 0; > } For implicit instantiation of a template, the point of instantiation is right after the function where it is used. So, at the point where less_equal<element> is instantiated, those using declarations are not visible. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
|
Pages: 1 Prev: Using std::less_equl predicate with std::min() Next: "PORTING C" > when to cast parameters? |