Jump to content

  • Log In with Google      Sign In   
  • Create Account

Kostikov Stas

Member Since 03 Jul 2007
Offline Last Active Mar 15 2014 01:16 PM

#5135583 Strange behavior of operator type

Posted by Kostikov Stas on 01 March 2014 - 01:09 AM


I thought you posted here because you wanted our opinions. We've worked with C++ for a similar amount of time, but I guess I have had worse experiences with types that can hold pretty much anything (we have them at work, and they are a headache) and unexpected implicit conversions.

 

Yes i wanted opinion on why code doesn't compiled. Not on why you think type free container is bad thing.  

 

My mistake i raise this theme here. 

 

I already say that i use template specialization, so it isn't code that you can use for any type without proper adjustment.

Just you don't need to rewrite original code for make this work.  If you want discuss it. You welcome to do it in private. I don't see how it's related to my question.




#5135525 Strange behavior of operator type

Posted by Kostikov Stas on 28 February 2014 - 05:53 PM

Overgeneralisation is overrated.
 
Example: I want to call a function which takes an unknown number of arguments of an arbitrary type. Here's the method to do that, yay! Now what does the function do with the arguments?
 
Abstraction is useful, of course.


Template specialization doesn't help?
template<typename type>
void convert( const std::string & s, type & t);

template<>
void convert( const std::string & s, int & a)
{
    a = atoi( s.c_str());
}

template<>
void convert( const string & s, float.& a)
{
    a = atof( s.c_str());
}

template< typename type>
type convert( const string & s )
{
   type t;
   conver( s, t);
   return t;
}
Template can be just declaration but you can specialize different realization for different cases.
So what problems with different list of arguments?


#5135505 Strange behavior of operator type

Posted by Kostikov Stas on 28 February 2014 - 05:04 PM

Please lets skip holy wars. It's the reason i don't want to discuss my code here. It's in c++ style and i have my reasons to use it. And i actually more interested why code doesn't compiled. Let say this is theoretical interest lets forget about my previous messages.

And before you start to explain what i should and what i shouldn't do in code, i know this, i have more than 13 years professional c++ experience, and more than 7 on lead position. Yes i do know which problems this code can create. And yes i know how to fix them.


#5135491 Strange behavior of operator type

Posted by Kostikov Stas on 28 February 2014 - 04:39 PM

There is no type conflict. And syntax correct this code was compiled on different compilers. Gcc for mac and ubuntu compiled this code without questions. As well as 2010 and 2013 visual studio. On this moment only visual studio 2012 doesn't compiled this code. I know how to make it compile but then all other compilers might be failed.

Yes i think you correct and this probably bug. When i asked this question i think there something with code wrong but look like code correct.


#5135412 Strange behavior of operator type

Posted by Kostikov Stas on 28 February 2014 - 11:27 AM

Mine code isn't variant type. It's much different and I don't see a point to discuss it here. My question was why code writen according standart  isn't compiled. 

Not why i shouldn't use this code. And i suggest to stay with topic question.




PARTNERS