By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,982 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,982 IT Pros & Developers. It's quick & easy.

comma overload semantics

P: n/a

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

error : 'B &FM::operator ,(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.

Aug 4 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
terminator wrote:
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
Aug 4 '07 #2

P: n/a
On 4 Srp, 13:54, terminator <farid.mehr...@gmail.comwrote:
the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:

error : 'B &FM::operator ,(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

Aug 4 '07 #3

P: n/a
On Aug 4, 7:06 pm, jpale...@web.de wrote:
On 4 Srp, 13:54, terminator <farid.mehr...@gmail.comwrote:


the following compiles unless the first line is uncommented .
when I try to uncomment the first line I get:
error : 'B &FM::operator ,(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.

Aug 4 '07 #4

P: n/a
On Aug 4, 3:08 pm, Barry <dh...@126.comwrote:
terminator wrote:
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
acctually I am so hindered.I have a .net7.I must look for a more
standard compiler.any suggestions?

regards,
FM.

Aug 4 '07 #5

P: n/a
terminator wrote:
On Aug 4, 3:08 pm, Barry <dh...@126.comwrote:
>terminator wrote:
>>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

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
Aug 4 '07 #6

P: n/a
On 2007-08-04 18:12, terminator wrote:
On Aug 4, 3:08 pm, Barry <dh...@126.comwrote:
>terminator wrote:
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

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.

--
Erik Wikström
Aug 4 '07 #7

P: n/a
/*
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<doublea;
std::string b("Test succeeded.");
std::cout << (a,b) << std::endl;
}

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

Aug 5 '07 #8

P: n/a
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.)

Aug 5 '07 #9

P: n/a
On Aug 5, 12:08 am, Erik Wikström <Erik-wikst...@telia.comwrote:
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.

Aug 6 '07 #10

P: n/a
On Aug 5, 10:29 pm, Tobias <goo...@tn-home.dewrote:
/*
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<doublea;
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.

Aug 6 '07 #11

P: n/a
On Aug 5, 12:08 am, Erik Wikström <Erik-wikst...@telia.comwrote:

any technical notes or warnings on the subject(comma overloading)?

regards,
FM.
Aug 6 '07 #12

P: n/a
On 2007-08-06 17:57, terminator wrote:
On Aug 5, 12:08 am, Erik Wikström <Erik-wikst...@telia.comwrote:

any technical notes or warnings on the subject(comma overloading)?
Don't.
http://www.parashift.com/c++-faq-lit...erloading.html point 20.

--
Erik Wiström
Aug 6 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.