Discussion:
Can not deduse template arguments std::rel_ops
(too old to reply)
Vladimir Grigoriev
2010-01-12 16:00:34 UTC
Permalink
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
]
Victor Bazarov
2010-01-12 16:49:23 UTC
Permalink
Post by Vladimir Grigoriev
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...
Post by Vladimir Grigoriev
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?
Post by Vladimir Grigoriev
Vladimir Grigoriev
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
Vladimir Grigoriev
2010-01-13 13:41:11 UTC
Permalink
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
Post by Victor Bazarov
Post by Vladimir Grigoriev
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...
Post by Vladimir Grigoriev
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?
Post by Vladimir Grigoriev
Vladimir Grigoriev
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
Igor Tandetnik
2010-01-13 14:03:49 UTC
Permalink
Post by Vladimir Grigoriev
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
zeromem
2010-01-12 17:26:42 UTC
Permalink
You probably need to move "#include <utility>" to before "#include
<map>" or whatever the master data type file is.
Post by Vladimir Grigoriev
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
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
]
Loading...