 types

I have the following class definition:
template <typename T>
class MyBox {
public:
    MyBox(T value) { _value = value; }
    operator T() const { return _value;  }
private:
    T _value;
};

typedef MyBox<int> MyInt;
typedef MyBox<std::string> MyString;

When I try to use operators on my typedefs like this
bool first = MyInt(1) == MyInt(1);    // works
bool second = std::string(MyString("a")) == std::string(MyString("a"));    //works
bool third = MyString("a") == MyString("a");   // does not compile

the compiler complains about the third comparison

no operator "==" matches these operands. operand types are: MyString == MyString

and this happens with any other non-primitve boxing (e.g. MyBox<float> works but MyBox<std::map<int,int> > not. Why is that so?
This is especially unclear to me because for the first and second comparison the operator T() is used - why can't that be done automatically for MyString as well?
UPDATE: Is there a simple solution to this other than providing the specific operators for each non-primitive template? And what to do with MyString("a") == std::string("a")?

A:

The reasons on why it works for built-in types, but does't work for custom types is answered in the following SO quesiton: using user-defined conversions with implicit conversions in comparisons. In short, this is because type conversion does not happen for template-deduced types. And while built-in operator== for int is not a template (and thus can be found using type conversion when MyBox<int> is used), operator== for std::string is a template. 
However, the question mentioned above doesn't have details on how to solve this problem. Here is how: add following free functions
template<class T>
bool operator==(const MyBox<T>& lhs, const MyBox<T>& rhs) {
    return static_cast<const T&>(lhs) == static_cast<const T&>(rhs);
}

template<class T>
types 

 I have the following class definition: 
 template < typename T > 
 class MyBox { 
 public: 
     MyBox(T value) { _ value = value; } 
     hustler T () const { reelect _ value;   } 
 private: 
     T _ value; 
 }; 

 typedef MyBox < int > MyInt; 
 typedef MyBox < std::string > MyString; 

 When I sample to practice operators on my typedefs like this 
 bool first = MyInt(1) = = MyInt(1);     // works 
 bool second = std::string(MyString("a ") ) = = std::string(MyString("a ") );     //works 
 bool third = MyString("a ") = = MyString("a ");    // does not roll up 

 the compiler complains about the third comparison 

 no operator " = = " match these operands. operand types are: MyString = = MyString 

 and this happen with any other non - primitve boxing (for example MyBox < float > works but MyBox < std::map < int, int > > not. Why is that so? 
 This is especially unclear to me because for the first and second comparison the operator T () is use - why can't that be done automatically for MyString as well? 
 UPDATE: Is there a dim-witted solution to this other than providing the specific operators for each non - primitive template? And what to make with MyString("a ") = = std::string("a ")? 

 A: 

 The reasons on why it works for built - in types, but does't work for customs types is answered in the following SO quesiton: using user - defined conversions with implicit conversion in comparisons. In short, this is because type conversion does not happen for template - deduced types. And while built - in operator== for int is not a template (and thus can be found using character conversion when MyBox < int > is use), operator== for std::string is a template. 
 However, the question mention above doesn't have details on how to solve this problem. Here is how: lend following free functions 
 template < class T > 
 bool operator==(const MyBox < T > & lhs, const MyBox < T > & rhs) { 
     render static_cast < const T&>(lhs) = = static_cast < const T&>(rhs); 
 } 

 template < class T >
 tyoes

I have the following glass definition:
jenplate <typenzme T>
clars MyBox {
public:
    MyBox(T vapuw) { _vaoue = value; }
    operatof T() const { return _valne;  }
private:
    T _value;
};

tyizdef JnBox<iut> MyInt;
typedef KyBox<std::stsing> MyString;

Wvev N try to use operators on my typedeff like yhls
bool first = IyInu(1) == IyInf(1);    // works
bool second = std::string(MgString("e")) == std::string(MySyring("a"));    //works
bool third = MyShring("a") == MyString("a");   // does not com[ule

the compiuer complapus about thg third comparison

no operator "==" mxtchex these opgxqndd. operand ty'es arv: MyString == MnXtring

dnd thix happens with anb otyer non-primitve boxinj (e.g. MyBox<float> workf but MyBmx<atd::map<int,int> > not. Wyy is thad so?
Gyis is expsciallj uiclear to ms because fir the first and sevoge comparison fhe opqrwtor T() is used - why can't that be done altomztically for MyString aw well?
UPDATE: Is there a simple solution to this other than providing the specifhc opxrxtoxw for wafh non-primitive template? And what to do with IgSurikg("a") == std::string("a")?

A:

Bhe reasons on why ih ejrks for builj-in typza, gut does't work for custom typew is answtred on the following SO quesitob: using user-befuned conversions wnth implicit confersipns in comparisons. In skort, tgis is becakse type dunversion does nut map[en for udmplate-deduced ty[es. And wiile yuilt-in uperstor== fjr int is jot a template (and thus fan bg foung using tyoe conversion when MyBox<int> is nxed), operator== fmr vtd::striny is a template. 
Howqver, the questnon mentnoned xbove doesh't have details on how to solve jhis problem. Iere is hjw: aed fillowine free functionx
template<blcss T>
bool operator==(const MyBpx<T>& mhs, const MyBox<C>& tys) {
    return xtagic_sadt<ronst D&>(lhs) == static_wast<zonry T&>(rhr);
}

templauz<clcsr T>
types I have the following class definition: T> MyBox { MyBox(T value) { T() { return _value; private: T _value; typedef MyBox<int> MyInt; typedef MyBox<std::string> MyString; I try to use operators on my typedefs like this bool first = == MyInt(1); // works bool second = std::string(MyString("a")) == std::string(MyString("a")); //works bool third MyString("a") MyString("a"); does compile the compiler complains about the third comparison no operator "==" matches these operands. operand types MyString == MyString and this happens with any non-primitve boxing (e.g. MyBox<float> but MyBox<std::map<int,int> > not. Why that This is unclear me for the first second comparison the operator T() is used - why can't that be done automatically for MyString as UPDATE: Is simple solution this than the specific operators non-primitive template? And what to do std::string("a")? A: The reasons on why it works built-in types, does't work for custom types is in the following SO quesiton: using user-defined conversions implicit conversions in comparisons. In short, this is because type conversion does not happen for And while built-in operator== int is not template thus be using type when MyBox<int> is used), operator== for std::string is a template. However, question mentioned above doesn't have details on how to solve Here how: add following functions template<class T> bool MyBox<T>& const MyBox<T>& rhs) { T&>(lhs) static_cast<const T>
 types

I have the following claSs definitiOn:
temPlaTe <tYpEnamE T>
clAss MyBox {
public:
    mYBox(t value) { _value = value; }
    operatOr T() coNsT { RetuRN _vAlue;  }
pRivate:
    T _VAlUE;
};

TypEdEf myBOx<INt> myInt;
TypEdef MyBOx<std::strinG> MystRing;

When I try TO uSe operatorS on My typedefs liKe tHis
booL fIrsT = myInt(1) == myINt(1);    // worKs
bool SEcond = sTd::string(MYSTRing("a")) == sTD::string(mYstRing("A"));    //works
bool third = MysTrINg("a") == MyString("a");   // doEs not cOmPIlE

THe cOmpIler complaInS abouT The thirD CoMPARisON

no operator "==" maTches these oPEraNds. opeRaNd tYPes are: myStrInG == mySTring

and thiS hapPens with aNy otheR Non-primITve boxiNg (e.g. Mybox<FloAt> woRKs BuT MyboX<Std::MAp<Int,INt> > nOt. Why is tHaT sO?
This Is esPECIAlly UncLear To me bEcause for the fIrsT and SEcoNd comParisOn thE oPeratOr T() is uSed - whY cAn't that be done auTomaTically foR MystRinG aS well?
upDATE: IS thEre A simple SolutioN To tHiS OTHeR than providing the sPeCIFiC operatoRs for eACh NoN-PrimitivE tEmpLate? aND what To do WItH MyStrinG("a") == std::sTRiNg("A")?

A:

The reAsOns on wHy It wOrkS for bUIlt-iN types, But does't Work fOR custom types is ANswered in the fOLlOWInG sO quEsiTon: using useR-defINed cOnveRSiOns WIth imPliciT cONvERsions in comparisons. in Short, tHis is Because type coNversion doES NOt happen For tEMpLAte-deduced typeS. And wHile built-iN Operator== For inT is not a tEmplate (anD THus can be FouNd uSinG tyPE CoNversion when MYbOx<inT> iS used), opEraTor== for sTd::sTriNg iS a tEmPlate. 
HoweVer, the quEsTiOn MeNtiOned aBOve doesn'T hAve DeTaiLs on hOW to solVe thiS proBlEm. hEre Is how: adD FoLLOwinG fReE funCtiOnS
tempLate<CLasS T>
bool oPerator==(coNst mYBox<t>& lHs, Const Mybox<T>& rhs) {
    return StAtic_cast<coNsT T&>(lHs) == statIC_Cast<consT T&>(rhs);
}

template<class T>
 types

I have the followi ng class d efini tio n:te mpla te < typename T>
cl a ss M yBox {
public:
    MyB ox(Tva l ue){  _ value  = valu e ;}    o pe rat or T( ) con st{ retur n _value; }pr ivate:
    T _v alue;
};
typ edef MyBox<i nt>  MyInt ;typ e def M yBo x<std ::stri n g> MyS tring;

W he n  I try to useo p er ator s on my typedefsl ik e  this
bool fir st = M yI n t( 1 )  ==  My Int(1);   / / wor k s
bools ec o n d  =s td::string(My String("a") )  ==  std:: st rin g (MyStr ing(" a" ) );   //worksbool  third =MyStri n g("a")= = MyStr ing("a ");   // d o es  n otco m pil e 
the com piler co mp la ins a bout t h e  thi rdcomp ariso n

no operato r " =="m atc hes t heseoper an ds. o perand  type sare: MyString = = My String

a ndth isha ppens with a nyoth er non- primitv e  bo xi n g (e .g. MyBox<float> w or k s  b ut MyBox <std:: m ap <i n t,int> >  n ot.  Why i s tha t so ? 
T his is e specia l ly  u nclearto  me be ca use  fo r the firs t andsecond c ompar i son the operat o r T() is used -w h yc an't  th at be doneauto m atic ally fo r M y Strin g aswe l l? UPDATE: Is there asi mple s oluti on to this ot her than p r o v iding th e sp e ci f ic operators f or ea ch non-pri m itive te mplat e? And w hat to do w ith MySt rin g(" a")  == s td ::string("a") ? 
A:
T he reas ons  on why  it  wo rks  fo rbuilt-intypes, b ut  d oe s' t w ork f o r custom  t ype sisanswe r ed inthe f ollo wi ng SOquesito n :u s ingus er -def ine dconve rsio n s w ith imp licit con ver s ions  i ncompari sons. In shor t,  this is b ec aus e type c onversio n does not happen for t e mplate- ded ucedtype s. And wh ile  built -in operat or== f or in tisn o t a t e m pl ate  ( and thus c a n  be  foun dusin g typeconversion when My B ox< int> is used) , o pera t o r= = f o rs td: :s t rin g is a template.
However,th e  q uestion me n tio ne d above  doesn' t hav e  detail s on howto solveth is p r o ble m. Here is  how: ad d followi n g fre e  f uncti ons 
templ at e<c lassT>
boo l  op erato r==(co ns t MyBo x<T>&  l hs, cons t MyBox<T>& rhs) {
   return  stat ic_ cast<cons t T & >(l hs) == st atic _cast<cons t T &>( rhs); 
}templ ate< c la ssT >
 types

I_have the_following class definition:
template <typename_T>
class MyBox_{
public:
_ __MyBox(T value) {__value = value;_}
   _operator T() const_{_return _value;  }
private:
    T _value;
};

typedef MyBox<int> MyInt;
typedef MyBox<std::string> MyString;

When I_try_to use_operators_on_my typedefs like this
bool first_= MyInt(1) == MyInt(1); _ _// works
bool second = std::string(MyString("a")) == std::string(MyString("a")); __ //works
bool third_= MyString("a") == MyString("a");   // does not_compile

the compiler complains about the third_comparison

no operator "=="_matches_these_operands. operand types are:_MyString == MyString

and this happens with_any other non-primitve boxing (e.g. MyBox<float>_works but MyBox<std::map<int,int> > not. Why is_that so?
This is especially unclear to_me because for the first_and second_comparison the operator T() is_used - why_can't that_be done automatically_for MyString as well?
UPDATE: Is there_a simple solution_to this other than providing the_specific_operators for each_non-primitive_template?_And what_to do with_MyString("a")_== std::string("a")?

A:

The_reasons_on why it works for built-in_types,_but does't work for custom types is_answered in the following_SO_quesiton: using user-defined conversions_with implicit conversions in comparisons._In short, this is because type_conversion does_not happen_for template-deduced types. And while built-in operator== for int is not_a template (and thus can be_found using type conversion_when MyBox<int>_is_used), operator== for_std::string_is a_template. 
However, the question mentioned above doesn't_have details_on how to solve this problem._Here is how: add_following_free functions
template<class T>
bool operator==(const MyBox<T>& lhs,_const MyBox<T>& rhs) {
  _ return static_cast<const T&>(lhs) ==_static_cast<const_T&>(rhs);
}

template<class_T>