I would like to apply the typef heterogeneous container discussed in C ++ to Effective Java in Bloch. The solution needs to be compiled in VS2010, but can use Boost if needed.
To be more specific I want to apply a class implementing the following interface
Abstract class IHeterogenousContainer {template < Typename T & gt; Virtual Eddy (Consta IKey & lt; T & amp; amp; key; const T & amp; price) = 0; Template & lt; Typename T & gt; Virtual T Received (const IKey & lt; T & gt; & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; }
Boost. Nobody does the work, basically what does this author show:
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Map & gt; # Include & lt; Typeindex & gt; #include & lt; Boost / any.hpp & gt; Square heterogenous_map: std :: map & lt; Std :: type_index, boost :: any & gt; {Public: Template & lt; Typename T & gt; Zero plus (T & amp; value) {emplace (typid (typename std :: remove_reference & lt; T & gt;: type), std :: forward & lt; T & gt; (value)); } Template & lt; Typename T & gt; T & amp; Get () {Return * boost :: any_cast & lt; T & gt; (And (typewrite (t)); } Template & lt; Typename T & gt; T const & amp; Get () const {return * boost :: any_cast & lt; T & gt; (And (typewrite (t)); }}; Int main () {heterogenous_map map; Map.add (6584); Map.add & lt; Std :: string & gt; ( "Oh!"); Std :: cout & lt; & Lt; "My favorite integer:" & lt; & Lt; Map.get & lt; Int & gt; () & Lt; & Lt; '\ N'; Std :: cout & lt; & Lt; "My favorite string:" & lt; & Lt; Map.get & lt; Std :: string & gt; () & Lt; & Lt; Std :: endl; }
.
Comments
Post a Comment