//Purpose: // demo "morphing" of metafunction grammar types to expression types. //Reference: // http://planetmath.org/encyclopedia/HomomorphismBetweenAlgebraicSystems.html #include #include #include using namespace boost::proto; template < class MetaFunInst //proto metafunction instantiation forming "metafunction" grammar. > struct morphism //algebraic morphism, Corresponds to the f in Reference. //The A algebra in Reference corresponds to the proto metafunction grammars. //The B algebra in Refernece corresponds to the proto expression types. ; typedef terminal metafun0_type; template < > struct morphism < metafun0_type //corresponds to application of nullary function in A algebra in Reference. > { typedef metafun0_type::type type; }; template < class Arg1 , templateclass MetaFun1 //corresponds to unary function in A algebra in Reference. > struct morphism < MetaFun1 //corresponds to application of unary function in A algebra in Reference. > { typedef typename MetaFun1 < typename morphism::type >::type type; }; typedef morphism::type morph0_type; typedef expr < tag::terminal , argsns_::args0 > expr0_type; BOOST_MPL_ASSERT((::boost::is_same)); typedef posit < metafun0_type > metafun1_type; typedef morphism::type morph1_type; typedef expr < tag::posit , argsns_::args1 > expr1_type; BOOST_MPL_ASSERT((::boost::is_same));