473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

comma overload semantics


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
12 2424
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
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
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
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
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
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
/*
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
6
by: Atlas | last post by:
It's said I can't throw an ostream object, so maybe I can overload "throw" for my basic_ostream derived class?
2
by: benben | last post by:
I am looking for a good example of overloading operator , (operator comma) Any suggestions? Ben
3
by: Elmo Watson | last post by:
I've been asked to develop a semi-automated type situation where we have a database table (sql server) and periodically, there will be a comma delimited file from which we need to import the data,...
5
by: Fabio Fracassi | last post by:
Hi, I belive what i am trying to do is not possible, but I hope someone can change my mind. Here is some code i'd like to write: template <class type> class engine1 {}; template <class...
9
by: Steve Sargent | last post by:
Hi: I'm trying to debug the following code, and it keeps looping on the if statement: public static bool operator == (OnlineMemberNode first, OnlineMemberNode second) { if(first == null) {
5
by: Shea Martin | last post by:
I have a struct like so: struct MyStruct { public: void Value( int newValue ) { mValue = newValue; } int Value() const { return mValue; } private: int mValue;
1
by: mr.gsingh | last post by:
My program looks something like this: int x = 23; if ( (func(x), func1(x), func2(x)) <= (foo(x), foo1(x), foo2(x))) { std::cout << "............"; } else { std::cout<< "..............";
3
by: sebastien.lannez | last post by:
Thanks for your quick response. Using Python as an algebraic parser for symbolic mathematical equation and I need that the 'in' operator returns an object based on its two arguments.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.