comma overload semantics

T

terminator

the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:

error : 'B &FM::eek:perator ,(FM::mystruct<A>,B &)' : could not deduce
template argument for 'FM::mystruct<A>' from
'std::basic_string<_Elem,_Traits,_Ax>::_Myt'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]

As long as 'mystruct' is a normal struct no error occures,but there is
some trouble with template version.

error refers to to the 'assign' method of
'std::basic_string<_Elem,_Traits,_Ax>' :

_Myt& assign(const _Myt& _Right, size_type _Roff, size_type _Count)
{ // assign _Right [_Roff, _Roff + _Count)
...//some code here
if (this == &_Right)
erase((size_type)(_Roff + _Num)), erase(0, _Roff);// substring
...//some code here
}

I am confused since 'mystruct' does not declare any ctors and normally
the compiler should not try to cast anything to it . So, after failure
to find the appropriate overload , the default version must be used .
Is there any problem with my compiler or I have to declare a default
version? I mean some thing like this:

template <typename A, typename B>
inline B& operator,(A &,B& b){return b;};//default comma in global
namespace

Is there any restriction on overloading comma?
What are the semantics for overloading comma?

//#define uncomment
#include <iostream>

#ifdef uncomment/*template version of mystruct*/
# define BiTemplate(A,B) template < typename A ,typename B >
# define UnoTemplate(A) template < typename A >
# define With(A) < A >
#else/*none template version of mystruct: ignore A .*/
# define BiTemplate(A,B) template < typename B >
# define UnoTemplate(A)
# define With(A)
#endif


namespace FM{

UnoTemplate(A)
struct mystruct{
};

BiTemplate(A,B)
B& operator,(mystruct With(A) ,B& i){return i;};

};
using namespace FM;

void main(void){};//just do nothing

Thanks in advance,
FM.
 
B

Barry

terminator said:
the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:

the code compiles here either uncommented or commented

using VC8 and icc 9.1
 
J

jpalecek

the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:

error : 'B &FM::eek:perator ,(FM::mystruct<A>,B &)' : could not deduce
template argument for 'FM::mystruct<A>' from
'std::basic_string<_Elem,_Traits,_Ax>::_Myt'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]

As long as 'mystruct' is a normal struct no error occures,but there is
some trouble with template version.

error refers to to the 'assign' method of
'std::basic_string<_Elem,_Traits,_Ax>' :

_Myt& assign(const _Myt& _Right, size_type _Roff, size_type _Count)
{ // assign _Right [_Roff, _Roff + _Count)
...//some code here
if (this == &_Right)
erase((size_type)(_Roff + _Num)), erase(0, _Roff);// substring
...//some code here
}

I am confused since 'mystruct' does not declare any ctors and normally
the compiler should not try to cast anything to it . So, after failure
to find the appropriate overload , the default version must be used .
Is there any problem with my compiler or I have to declare a default
version? I mean some thing like this:

template <typename A, typename B>
inline B& operator,(A &,B& b){return b;};//default comma in global
namespace

Is there any restriction on overloading comma?
What are the semantics for overloading comma?

//#define uncomment
#include <iostream>

#ifdef uncomment/*template version of mystruct*/
# define BiTemplate(A,B) template < typename A ,typename B >
# define UnoTemplate(A) template < typename A >
# define With(A) < A >
#else/*none template version of mystruct: ignore A .*/
# define BiTemplate(A,B) template < typename B >
# define UnoTemplate(A)
# define With(A)
#endif

namespace FM{

UnoTemplate(A)
struct mystruct{
};

BiTemplate(A,B)
B& operator,(mystruct With(A) ,B& i){return i;};

};

using namespace FM;

void main(void){};//just do nothing

Thanks in advance,

Are you using Microsoft Visual Studio Express 2005? I see the same
error
here (not with your code, though). It seems VS is not applying SFINAE
correctly for some reason (I guess). Or it is somehow relating totally
unrelated code (your comma vs. normal ystem comma, which should be
used
in assign).

I think it is a bug in compiler.

Regards
Jiri Palecek
 
T

terminator

the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:
error : 'B &FM::eek:perator ,(FM::mystruct<A>,B &)' : could not deduce
template argument for 'FM::mystruct<A>' from
'std::basic_string<_Elem,_Traits,_Ax>::_Myt'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
As long as 'mystruct' is a normal struct no error occures,but there is
some trouble with template version.
error refers to to the 'assign' method of
'std::basic_string<_Elem,_Traits,_Ax>' :
_Myt& assign(const _Myt& _Right, size_type _Roff, size_type _Count)
{ // assign _Right [_Roff, _Roff + _Count)
...//some code here
if (this == &_Right)
erase((size_type)(_Roff + _Num)), erase(0, _Roff);// substring
...//some code here
}
I am confused since 'mystruct' does not declare any ctors and normally
the compiler should not try to cast anything to it . So, after failure
to find the appropriate overload , the default version must be used .
Is there any problem with my compiler or I have to declare a default
version? I mean some thing like this:
template <typename A, typename B>
inline B& operator,(A &,B& b){return b;};//default comma in global
namespace
Is there any restriction on overloading comma?
What are the semantics for overloading comma?
//#define uncomment
#include <iostream>
#ifdef uncomment/*template version of mystruct*/
# define BiTemplate(A,B) template < typename A ,typename B >
# define UnoTemplate(A) template < typename A >
# define With(A) < A >
#else/*none template version of mystruct: ignore A .*/
# define BiTemplate(A,B) template < typename B >
# define UnoTemplate(A)
# define With(A)
#endif
namespace FM{
UnoTemplate(A)
struct mystruct{
};
BiTemplate(A,B)
B& operator,(mystruct With(A) ,B& i){return i;};

using namespace FM;
void main(void){};//just do nothing
Thanks in advance,

Are you using Microsoft Visual Studio Express 2005? I see the same
error
here (not with your code, though). It seems VS is not applying SFINAE
correctly for some reason (I guess). Or it is somehow relating totally
unrelated code (your comma vs. normal ystem comma, which should be
used
in assign).

I think it is a bug in compiler.

I guess so.

thanks a lot,
FM.
 
T

terminator

the code compiles here either uncommented or commented

using VC8 and icc 9.1

acctually I am so hindered.I have a .net7.I must look for a more
standard compiler.any suggestions?

regards,
FM.
 
B

Barry

terminator said:
acctually I am so hindered.I have a .net7.I must look for a more
standard compiler.any suggestions?

regards,
FM.

I think I have no suggestion, here I just use C++ for about one year
:), the compilers I often use are vc6 vc8 and icc9.1
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

acctually I am so hindered.I have a .net7.I must look for a more
standard compiler.any suggestions?

Depending on your needs Visual C++ 2005 Express might suffice, the
compiler is the same as in Visual Studio 2005 but the GUI is more
limited. If that is not enough you have to either pay of find an open
source solution built around gcc.
 
T

Tobias

/*
The program compiles and works
with g++ from gcc-Version 3.3.5 (Debian 1:3.3.5-13).
The used program:
*/
#include <iostream>
#include <string>

template<typename A>
struct mystruct{
};

template<typename A,typename B>
B& operator,(mystruct<A> ,B& i){return i;};


int main(void){
mystruct<double> a;
std::string b("Test succeeded.");
std::cout << (a,b) << std::endl;
}

/*
The command line and the output:
g++ test.cc; ./a.out;
Test succeeded.
*/
 
T

Tobias

Just to mention it: There are other issues with Visual Studio 2005.
For an instance the implementation of std::auto_ptr is a mess. It uses
some type casting to void* instead of the proper template
implementation. For that reason it is almost impossible to use dynamic
type casting with this version of std::auto_ptr. (With g++
std::auto_ptr works fine.)
 
T

terminator

Depending on your needs Visual C++ 2005 Express might suffice, the
compiler is the same as in Visual Studio 2005 but the GUI is more
limited.

Vs2005 is easy 4 me to get.
If that is not enough you have to either pay of find an open
source solution built around gcc.

any link or comment on this one?(I mean true open source one with its
source).I am starting a search.

thanks,
FM.
 
T

terminator

/*
The program compiles and works
with g++ from gcc-Version 3.3.5 (Debian 1:3.3.5-13).
The used program:
*/
#include <iostream>
#include <string>

template<typename A>
struct mystruct{

};

template<typename A,typename B>
B& operator,(mystruct<A> ,B& i){return i;};

int main(void){
mystruct<double> a;
std::string b("Test succeeded.");
std::cout << (a,b) << std::endl;

}

/*
The command line and the output:
g++ test.cc; ./a.out;
Test succeeded.
*/

I am urged that this is a bug in my compiler.

thanks for testing.

regards,
FM.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top